From 954ba1c0b4604ea2bd5bad3881408bbc9bafd0f2 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 13 Nov 2013 14:32:02 +0100 Subject: [PATCH 1/4] Remove test functions in loop whenever it's possible --- .../Phrasea/TaskManager/Job/ArchiveJob.php | 28 +++++++++++++++---- lib/classes/unicode.php | 3 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php index 95e2ca80e2..44fc0eab3f 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/ArchiveJob.php @@ -366,9 +366,13 @@ class ArchiveJob extends AbstractJob $xpath = new \DOMXPath($dom); - for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) { + for ($n = $node->firstChild; $n; $n = $n->nextSibling) { usleep(10); + if (!$this->isStarted()) { + break; + } + // make xml lighter (free ram) foreach (array("size", "ctime", "mtime") as $k) { $n->removeAttribute($k); @@ -472,7 +476,10 @@ class ArchiveJob extends AbstractJob } // scan again for unmatched files - for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) { + for ($n = $node->firstChild; $n; $n = $n->nextSibling) { + if (!$this->isStarted()) { + break; + } if (!$n->getAttribute('isdir') == '1' && !$n->getAttribute('match')) { // still no match, now it's an error (bubble to the top) for ($nn = $n; $nn && $nn->nodeType == XML_ELEMENT_NODE; $nn = $nn->parentNode) { @@ -492,9 +499,13 @@ class ArchiveJob extends AbstractJob } $nodesToDel = array(); - for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) { + for ($n = $node->firstChild; $n; $n = $n->nextSibling) { usleep(10); + if (!$this->isStarted()) { + break; + } + if ($n->getAttribute('temperature') == 'hot') { // do not move hotfiles continue; @@ -557,9 +568,13 @@ class ArchiveJob extends AbstractJob } $nodesToDel = array(); - for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) { + for ($n = $node->firstChild; $n; $n = $n->nextSibling) { usleep(10); + if (!$this->isStarted()) { + break; + } + if ($n->getAttribute('temperature') == 'hot') { continue; } @@ -1082,7 +1097,10 @@ class ArchiveJob extends AbstractJob private function archiveFilesToGrp(Application $app, \databox $databox, \DOMDocument $dom, \DOMElement $node, $path, $path_archived, $path_error, $grp_rid, $stat0, $stat1, $moveError, $moveArchived) { $nodesToDel = array(); - for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) { + for ($n = $node->firstChild; $n; $n = $n->nextSibling) { + if (!$this->isStarted()) { + break; + } if ($n->getAttribute('isdir') == '1') { // in a grp, all levels goes in the same grp $node->setAttribute('archived', '1'); // the main grp folder is 'keep'ed, but not subfolders diff --git a/lib/classes/unicode.php b/lib/classes/unicode.php index e1be36814b..12e38f1b93 100644 --- a/lib/classes/unicode.php +++ b/lib/classes/unicode.php @@ -1586,8 +1586,9 @@ class unicode $out = ''; $_map = &self::$map[$target]; // faster in loop + $length = mb_strlen($string, 'UTF-8'); - for ($i = 0; $i < mb_strlen($string, 'UTF-8'); $i++) { + for ($i = 0; $i < $length; $i++) { if (true === array_key_exists(($c = mb_substr($string, $i, 1, 'UTF-8')), $_map)) { $out .= $_map[$c]; } else { From 3e9f3418ce4c11badf5cf8d40ed975d5c966467a Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 13 Nov 2013 14:48:34 +0100 Subject: [PATCH 2/4] Remove dead code --- lib/Alchemy/Phrasea/Cache/Factory.php | 12 ++++++------ lib/Alchemy/Phrasea/Command/Command.php | 4 ++-- lib/Alchemy/Phrasea/Controller/Admin/Users.php | 10 +++++----- lib/Alchemy/Phrasea/Controller/Datafiles.php | 2 +- lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php | 12 +----------- .../Phrasea/TaskManager/Job/RecordMoverJob.php | 11 ----------- 6 files changed, 15 insertions(+), 36 deletions(-) diff --git a/lib/Alchemy/Phrasea/Cache/Factory.php b/lib/Alchemy/Phrasea/Cache/Factory.php index 2b9a2bd040..9273c9499a 100644 --- a/lib/Alchemy/Phrasea/Cache/Factory.php +++ b/lib/Alchemy/Phrasea/Cache/Factory.php @@ -42,7 +42,7 @@ class Factory switch (strtolower($name)) { case 'apc': case 'apccache': - $cache = $this->createApc($options); + $cache = $this->createApc(); break; case 'array': case 'arraycache': @@ -62,11 +62,11 @@ class Factory break; case 'wincache': case 'wincachecache': - $cache = $this->createWincache($options); + $cache = $this->createWincache(); break; case 'xcache': case 'xcachecache': - $cache = $this->createXcache($options); + $cache = $this->createXcache(); break; default: throw new RuntimeException(sprintf('Unnown cache type %s', $name)); @@ -75,7 +75,7 @@ class Factory return $cache; } - private function createXcache($options) + private function createXcache() { if (!extension_loaded('xcache')) { throw new RuntimeException('The XCache cache requires the XCache extension.'); @@ -84,7 +84,7 @@ class Factory return new XcacheCache(); } - private function createWincache($options) + private function createWincache() { if (!extension_loaded('wincache')) { throw new RuntimeException('The WinCache cache requires the WinCache extension.'); @@ -123,7 +123,7 @@ class Factory return $cache; } - private function createApc($options) + private function createApc() { if (!extension_loaded('apc')) { throw new RuntimeException('The APC cache requires the APC extension.'); diff --git a/lib/Alchemy/Phrasea/Command/Command.php b/lib/Alchemy/Phrasea/Command/Command.php index 95141285a5..1f80d7d304 100644 --- a/lib/Alchemy/Phrasea/Command/Command.php +++ b/lib/Alchemy/Phrasea/Command/Command.php @@ -55,14 +55,14 @@ abstract class Command extends SymfoCommand implements CommandInterface $handler = new StreamHandler('php://stdout', $level); $this->container['monolog'] = $this->container->share( - $this->container->extend('monolog', function ($logger, $app) use ($handler) { + $this->container->extend('monolog', function ($logger) use ($handler) { $logger->pushHandler($handler); return $logger; }) ); $this->container['task-manager.logger'] = $this->container->share( - $this->container->extend('task-manager.logger', function ($logger, $app) use ($handler) { + $this->container->extend('task-manager.logger', function ($logger) use ($handler) { $logger->pushHandler($handler); return $logger; diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index 14a0cdca95..d54e3b58b9 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -31,7 +31,7 @@ class Users implements ControllerProviderInterface $controllers = $app['controllers_factory']; - $controllers->before(function (Request $request) use ($app) { + $controllers->before(function (Request $request, Application $app) { $app['firewall']->requireAccessToModule('admin') ->requireRight('manageusers'); }); @@ -350,7 +350,7 @@ class Users implements ControllerProviderInterface return $response; })->bind('admin_users_export_csv'); - $controllers->get('/demands/', function (Application $app, Request $request) { + $controllers->get('/demands/', function (Application $app) { $lastMonth = time() - (3 * 4 * 7 * 24 * 60 * 60); $sql = "DELETE FROM demand WHERE date_modif < :date"; @@ -689,7 +689,7 @@ class Users implements ControllerProviderInterface $passwordToVerif = $value; if ($passwordToVerif === "") { - $out['errors'][] = sprintf(_("Password is empty at line %d"), $i); + $out['errors'][] = sprintf(_("Password is empty at line %d"), $nbLine); } else { $pwdValid = true; } @@ -870,7 +870,7 @@ class Users implements ControllerProviderInterface return $app->redirectPath('admin_users_search', array('user-updated' => $nbCreation)); })->bind('users_submit_import'); - $controllers->get('/import/example/csv/', function (Application $app, Request $request) { + $controllers->get('/import/example/csv/', function (Application $app) { $file = new \SplFileInfo($app['root.path'] . '/lib/Fixtures/exampleImportUsers.csv'); @@ -889,7 +889,7 @@ class Users implements ControllerProviderInterface return $response; })->bind('users_import_csv'); - $controllers->get('/import/example/rtf/', function (Application $app, Request $request) { + $controllers->get('/import/example/rtf/', function (Application $app) { $file = new \SplFileInfo($app['root.path'] . '/lib/Fixtures/Fields.rtf'); diff --git a/lib/Alchemy/Phrasea/Controller/Datafiles.php b/lib/Alchemy/Phrasea/Controller/Datafiles.php index bef54978e7..5680565aac 100644 --- a/lib/Alchemy/Phrasea/Controller/Datafiles.php +++ b/lib/Alchemy/Phrasea/Controller/Datafiles.php @@ -32,7 +32,7 @@ class Datafiles extends AbstractDelivery $that = $this; - $controllers->before(function (Request $request) use ($app) { + $controllers->before(function () use ($app) { if (!$app['authentication']->isAuthenticated()) { $app->abort(403, 'You are not autorized to see this'); } diff --git a/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php b/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php index 5f150dc91b..0b03012c7e 100644 --- a/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php +++ b/lib/Alchemy/Phrasea/Controller/Thesaurus/Xmlhttp.php @@ -912,13 +912,9 @@ class Xmlhttp implements ControllerProviderInterface } if ($dom) { - $term0 = ''; - $firstTerm0 = ''; - $xpath = new \DOMXPath($dom); if ($thid == 'T' || $thid == 'C') { $q = '/' . $xqroot; - $term0 = $dbname; } else { $q = '/' . $xqroot . '//te[@id=\'' . $thid . '\']'; } @@ -1400,7 +1396,7 @@ class Xmlhttp implements ControllerProviderInterface $xp = '//te[@id="' . $tid . '"]/sy'; $nodes = $xpathct->query($xp); if ($nodes->length == 1) { - $sy = $term = $nodes->item(0); + $sy = $nodes->item(0); $syid = str_replace('.', 'd', $sy->getAttribute('id')) . 'd'; $lid .= ( $lid ? ',' : '') . "'" . $syid . "'"; $field = $sy->parentNode->parentNode->getAttribute('field'); @@ -1533,7 +1529,6 @@ class Xmlhttp implements ControllerProviderInterface $html = ''; $sbid = (int) $request->get('sbid'); - $dbname = ''; try { $databox = $app['phraseanet.appbox']->get_databox($sbid); @@ -1710,9 +1705,4 @@ class Xmlhttp implements ControllerProviderInterface } } } - - private function call($method) - { - return sprintf('%s::%s', __CLASS__, $method); - } } diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/RecordMoverJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/RecordMoverJob.php index b46bd6c716..720d360df6 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/RecordMoverJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/RecordMoverJob.php @@ -255,10 +255,6 @@ class RecordMoverJob extends AbstractJob $tw[] = $tws[0]; elseif (count($tws) > 1) $tw[] = '(' . implode(') OR (', $tws) . ')'; - if (count($tw) == 1) - $where = $tw[0]; - if (count($tw) > 1) - $where = '(' . implode(') AND (', $tw) . ')'; // build the TEST sql (select) $sql_test = 'SELECT record_id FROM record' . $join; @@ -433,13 +429,6 @@ class RecordMoverJob extends AbstractJob $tw[] = '(status&0b' . $ma . ")=0"; } - if (count($tw) == 1) { - $where = $tw[0]; - } - if (count($tw) > 1) { - $where = '(' . implode(') AND (', $tw) . ')'; - } - return array($tw, $join); } } From 73e0d5cb6b71fa96dd6e16864ab604426e4c375b Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 13 Nov 2013 14:48:49 +0100 Subject: [PATCH 3/4] Remove thesaurus patchs globals, cleanup --- .../Phrasea/Controller/Thesaurus/Thesaurus.php | 2 +- lib/classes/patchthesaurus/100.php | 17 +++++------------ lib/classes/patchthesaurus/200.php | 10 ++-------- lib/classes/patchthesaurus/201.php | 10 ++-------- lib/classes/patchthesaurus/202.php | 10 ++-------- lib/classes/patchthesaurus/203.php | 16 +++------------- lib/classes/patchthesaurus/204.php | 16 +++------------- 7 files changed, 18 insertions(+), 63 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php b/lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php index 39b55ab609..a8e0296653 100644 --- a/lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php +++ b/lib/Alchemy/Phrasea/Controller/Thesaurus/Thesaurus.php @@ -1039,7 +1039,7 @@ class Thesaurus implements ControllerProviderInterface $last_version = $version; $zcls = new $cls; - $version = $zcls->patch($version, $domct, $domth, $connbas); + $version = $zcls->patch($version, $domct, $domth, $connbas, $app['unicode']); if ($version == $last_version) { break; diff --git a/lib/classes/patchthesaurus/100.php b/lib/classes/patchthesaurus/100.php index b89ad77b31..1e4ee8ed92 100644 --- a/lib/classes/patchthesaurus/100.php +++ b/lib/classes/patchthesaurus/100.php @@ -9,15 +9,9 @@ * file that was distributed with this source code. */ -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -class patchthesaurus_100 +class patchthesaurus_100 implements patchthesaurus_interface { - - public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas) + public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) { if ($version == "") { $th = $domth->documentElement; @@ -37,7 +31,7 @@ class patchthesaurus_100 } foreach ($te1 as $tei) { $th->appendChild($tei); - $this->fixThesaurus2($domth, $tei); + $this->fixThesaurus2($domth, $tei, 0, $unicode); // $tei->parentNode->removeChild($tei); } $te0->parentNode->removeChild($te0); @@ -52,9 +46,8 @@ class patchthesaurus_100 return($version); } - public function fixThesaurus2(&$domth, &$tenode, $depth = 0) + private function fixThesaurus2(&$domth, &$tenode, $depth, \unicode $unicode) { - $unicode = new unicode(); $sy = $tenode->appendChild($domth->createElement("sy")); $sy->setAttribute("lng", $v = $tenode->getAttribute("lng")); $sy->setAttribute("v", $v = $tenode->getAttribute("v")); @@ -73,7 +66,7 @@ class patchthesaurus_100 if ($n->nodeName == "ta") $todel[] = $n; if ($n->nodeName == "te") - $this->fixThesaurus2($domth, $n, $depth + 1); + $this->fixThesaurus2($domth, $n, $depth + 1, $unicode); } foreach ($todel as $n) { $n->parentNode->removeChild($n); diff --git a/lib/classes/patchthesaurus/200.php b/lib/classes/patchthesaurus/200.php index 44e61f469d..2c083c060d 100644 --- a/lib/classes/patchthesaurus/200.php +++ b/lib/classes/patchthesaurus/200.php @@ -9,15 +9,9 @@ * file that was distributed with this source code. */ -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -class patchthesaurus_200 +class patchthesaurus_200 implements patchthesaurus_interface { - - public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas) + public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) { if ($version == "2.0.0") { $th = $domth->documentElement; diff --git a/lib/classes/patchthesaurus/201.php b/lib/classes/patchthesaurus/201.php index 5b5a22ef8e..2c2e053405 100644 --- a/lib/classes/patchthesaurus/201.php +++ b/lib/classes/patchthesaurus/201.php @@ -9,15 +9,9 @@ * file that was distributed with this source code. */ -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -class patchthesaurus_201 +class patchthesaurus_201 implements patchthesaurus_interface { - - public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas) + public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) { if ($version == "2.0.1") { $th = $domth->documentElement; diff --git a/lib/classes/patchthesaurus/202.php b/lib/classes/patchthesaurus/202.php index aea05afaf2..2b43a35229 100644 --- a/lib/classes/patchthesaurus/202.php +++ b/lib/classes/patchthesaurus/202.php @@ -9,15 +9,9 @@ * file that was distributed with this source code. */ -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -class patchthesaurus_202 +class patchthesaurus_202 implements patchthesaurus_interface { - - public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas) + public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) { if ($version == "2.0.2") { $th = $domth->documentElement; diff --git a/lib/classes/patchthesaurus/203.php b/lib/classes/patchthesaurus/203.php index 17f45eea98..fc88598a59 100644 --- a/lib/classes/patchthesaurus/203.php +++ b/lib/classes/patchthesaurus/203.php @@ -9,18 +9,11 @@ * file that was distributed with this source code. */ -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -class patchthesaurus_203 +class patchthesaurus_203 implements patchthesaurus_interface { - - public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas) + public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) { - global $ctchanged, $thchanged, $needreindex; - $unicode = new unicode(); + $needreindex = false; if ($version == "2.0.3") { $xp = new DOMXPath($domth); @@ -46,8 +39,6 @@ class patchthesaurus_203 $domth->documentElement->setAttribute("version", "2.0.4"); $domth->documentElement->setAttribute("modification_date", date("YmdHis")); - $thchanged = true; - if ($needreindex) { print("// need to reindex, deleting cterms (keeping rejected)\n"); @@ -95,7 +86,6 @@ class patchthesaurus_203 $domct->documentElement->setAttribute("version", "2.0.4"); $domct->documentElement->setAttribute("modification_date", date("YmdHis")); - $ctchanged = true; $version = "2.0.4"; } diff --git a/lib/classes/patchthesaurus/204.php b/lib/classes/patchthesaurus/204.php index d177fd30fc..3719cee4c9 100644 --- a/lib/classes/patchthesaurus/204.php +++ b/lib/classes/patchthesaurus/204.php @@ -9,19 +9,12 @@ * file that was distributed with this source code. */ -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -class patchthesaurus_204 +class patchthesaurus_204 implements patchthesaurus_interface { - - public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas) + public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode) { - global $ctchanged, $thchanged, $needreindex; + $needreindex = false; - $unicode = new unicode(); if ($version == "2.0.4") { $xp = new DOMXPath($domth); $sy = $xp->query("//sy"); @@ -46,8 +39,6 @@ class patchthesaurus_204 $domth->documentElement->setAttribute("version", "2.0.5"); $domth->documentElement->setAttribute("modification_date", date("YmdHis")); - $thchanged = true; - if ($needreindex) { print("// need to reindex, deleting cterms (keeping rejected)\n"); @@ -97,7 +88,6 @@ class patchthesaurus_204 $domct->documentElement->setAttribute("version", "2.0.5"); $domct->documentElement->setAttribute("modification_date", date("YmdHis")); - $ctchanged = true; $version = "2.0.5"; } From d974da8be16d24e27b4facc5e7d9244ce8eeebfc Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 13 Nov 2013 14:53:27 +0100 Subject: [PATCH 4/4] Remove user specific files from gitignore --- .gitignore | 1 - lib/classes/patchthesaurus/interface.php | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 lib/classes/patchthesaurus/interface.php diff --git a/.gitignore b/.gitignore index 19dc866ed1..b7a1f4492c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ /config/status /config/stamp /config/configuration.yml -.DS_Store /vendor /plugins /node_modules diff --git a/lib/classes/patchthesaurus/interface.php b/lib/classes/patchthesaurus/interface.php new file mode 100644 index 0000000000..ff7982fd52 --- /dev/null +++ b/lib/classes/patchthesaurus/interface.php @@ -0,0 +1,15 @@ +