Merge pull request #784 from romainneutron/insight-recommendations

[3.9] Insight recommendations
This commit is contained in:
Romain Neutron
2013-11-13 22:48:33 -08:00
17 changed files with 73 additions and 106 deletions

1
.gitignore vendored
View File

@@ -7,7 +7,6 @@
/config/status /config/status
/config/stamp /config/stamp
/config/configuration.yml /config/configuration.yml
.DS_Store
/vendor /vendor
/plugins /plugins
/node_modules /node_modules

View File

@@ -42,7 +42,7 @@ class Factory
switch (strtolower($name)) { switch (strtolower($name)) {
case 'apc': case 'apc':
case 'apccache': case 'apccache':
$cache = $this->createApc($options); $cache = $this->createApc();
break; break;
case 'array': case 'array':
case 'arraycache': case 'arraycache':
@@ -62,11 +62,11 @@ class Factory
break; break;
case 'wincache': case 'wincache':
case 'wincachecache': case 'wincachecache':
$cache = $this->createWincache($options); $cache = $this->createWincache();
break; break;
case 'xcache': case 'xcache':
case 'xcachecache': case 'xcachecache':
$cache = $this->createXcache($options); $cache = $this->createXcache();
break; break;
default: default:
throw new RuntimeException(sprintf('Unnown cache type %s', $name)); throw new RuntimeException(sprintf('Unnown cache type %s', $name));
@@ -75,7 +75,7 @@ class Factory
return $cache; return $cache;
} }
private function createXcache($options) private function createXcache()
{ {
if (!extension_loaded('xcache')) { if (!extension_loaded('xcache')) {
throw new RuntimeException('The XCache cache requires the XCache extension.'); throw new RuntimeException('The XCache cache requires the XCache extension.');
@@ -84,7 +84,7 @@ class Factory
return new XcacheCache(); return new XcacheCache();
} }
private function createWincache($options) private function createWincache()
{ {
if (!extension_loaded('wincache')) { if (!extension_loaded('wincache')) {
throw new RuntimeException('The WinCache cache requires the WinCache extension.'); throw new RuntimeException('The WinCache cache requires the WinCache extension.');
@@ -123,7 +123,7 @@ class Factory
return $cache; return $cache;
} }
private function createApc($options) private function createApc()
{ {
if (!extension_loaded('apc')) { if (!extension_loaded('apc')) {
throw new RuntimeException('The APC cache requires the APC extension.'); throw new RuntimeException('The APC cache requires the APC extension.');

View File

@@ -55,14 +55,14 @@ abstract class Command extends SymfoCommand implements CommandInterface
$handler = new StreamHandler('php://stdout', $level); $handler = new StreamHandler('php://stdout', $level);
$this->container['monolog'] = $this->container->share( $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); $logger->pushHandler($handler);
return $logger; return $logger;
}) })
); );
$this->container['task-manager.logger'] = $this->container->share( $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); $logger->pushHandler($handler);
return $logger; return $logger;

View File

@@ -31,7 +31,7 @@ class Users implements ControllerProviderInterface
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->before(function (Request $request) use ($app) { $controllers->before(function (Request $request, Application $app) {
$app['firewall']->requireAccessToModule('admin') $app['firewall']->requireAccessToModule('admin')
->requireRight('manageusers'); ->requireRight('manageusers');
}); });
@@ -350,7 +350,7 @@ class Users implements ControllerProviderInterface
return $response; return $response;
})->bind('admin_users_export_csv'); })->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); $lastMonth = time() - (3 * 4 * 7 * 24 * 60 * 60);
$sql = "DELETE FROM demand WHERE date_modif < :date"; $sql = "DELETE FROM demand WHERE date_modif < :date";
@@ -689,7 +689,7 @@ class Users implements ControllerProviderInterface
$passwordToVerif = $value; $passwordToVerif = $value;
if ($passwordToVerif === "") { if ($passwordToVerif === "") {
$out['errors'][] = sprintf(_("Password is empty at line %d"), $i); $out['errors'][] = sprintf(_("Password is empty at line %d"), $nbLine);
} else { } else {
$pwdValid = true; $pwdValid = true;
} }
@@ -870,7 +870,7 @@ class Users implements ControllerProviderInterface
return $app->redirectPath('admin_users_search', array('user-updated' => $nbCreation)); return $app->redirectPath('admin_users_search', array('user-updated' => $nbCreation));
})->bind('users_submit_import'); })->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'); $file = new \SplFileInfo($app['root.path'] . '/lib/Fixtures/exampleImportUsers.csv');
@@ -889,7 +889,7 @@ class Users implements ControllerProviderInterface
return $response; return $response;
})->bind('users_import_csv'); })->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'); $file = new \SplFileInfo($app['root.path'] . '/lib/Fixtures/Fields.rtf');

View File

@@ -32,7 +32,7 @@ class Datafiles extends AbstractDelivery
$that = $this; $that = $this;
$controllers->before(function (Request $request) use ($app) { $controllers->before(function () use ($app) {
if (!$app['authentication']->isAuthenticated()) { if (!$app['authentication']->isAuthenticated()) {
$app->abort(403, 'You are not autorized to see this'); $app->abort(403, 'You are not autorized to see this');
} }

View File

@@ -1039,7 +1039,7 @@ class Thesaurus implements ControllerProviderInterface
$last_version = $version; $last_version = $version;
$zcls = new $cls; $zcls = new $cls;
$version = $zcls->patch($version, $domct, $domth, $connbas); $version = $zcls->patch($version, $domct, $domth, $connbas, $app['unicode']);
if ($version == $last_version) { if ($version == $last_version) {
break; break;

View File

@@ -912,13 +912,9 @@ class Xmlhttp implements ControllerProviderInterface
} }
if ($dom) { if ($dom) {
$term0 = '';
$firstTerm0 = '';
$xpath = new \DOMXPath($dom); $xpath = new \DOMXPath($dom);
if ($thid == 'T' || $thid == 'C') { if ($thid == 'T' || $thid == 'C') {
$q = '/' . $xqroot; $q = '/' . $xqroot;
$term0 = $dbname;
} else { } else {
$q = '/' . $xqroot . '//te[@id=\'' . $thid . '\']'; $q = '/' . $xqroot . '//te[@id=\'' . $thid . '\']';
} }
@@ -1400,7 +1396,7 @@ class Xmlhttp implements ControllerProviderInterface
$xp = '//te[@id="' . $tid . '"]/sy'; $xp = '//te[@id="' . $tid . '"]/sy';
$nodes = $xpathct->query($xp); $nodes = $xpathct->query($xp);
if ($nodes->length == 1) { if ($nodes->length == 1) {
$sy = $term = $nodes->item(0); $sy = $nodes->item(0);
$syid = str_replace('.', 'd', $sy->getAttribute('id')) . 'd'; $syid = str_replace('.', 'd', $sy->getAttribute('id')) . 'd';
$lid .= ( $lid ? ',' : '') . "'" . $syid . "'"; $lid .= ( $lid ? ',' : '') . "'" . $syid . "'";
$field = $sy->parentNode->parentNode->getAttribute('field'); $field = $sy->parentNode->parentNode->getAttribute('field');
@@ -1533,7 +1529,6 @@ class Xmlhttp implements ControllerProviderInterface
$html = ''; $html = '';
$sbid = (int) $request->get('sbid'); $sbid = (int) $request->get('sbid');
$dbname = '';
try { try {
$databox = $app['phraseanet.appbox']->get_databox($sbid); $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);
}
} }

View File

@@ -366,9 +366,13 @@ class ArchiveJob extends AbstractJob
$xpath = new \DOMXPath($dom); $xpath = new \DOMXPath($dom);
for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) { for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
usleep(10); usleep(10);
if (!$this->isStarted()) {
break;
}
// make xml lighter (free ram) // make xml lighter (free ram)
foreach (array("size", "ctime", "mtime") as $k) { foreach (array("size", "ctime", "mtime") as $k) {
$n->removeAttribute($k); $n->removeAttribute($k);
@@ -472,7 +476,10 @@ class ArchiveJob extends AbstractJob
} }
// scan again for unmatched files // 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')) { if (!$n->getAttribute('isdir') == '1' && !$n->getAttribute('match')) {
// still no match, now it's an error (bubble to the top) // still no match, now it's an error (bubble to the top)
for ($nn = $n; $nn && $nn->nodeType == XML_ELEMENT_NODE; $nn = $nn->parentNode) { for ($nn = $n; $nn && $nn->nodeType == XML_ELEMENT_NODE; $nn = $nn->parentNode) {
@@ -492,9 +499,13 @@ class ArchiveJob extends AbstractJob
} }
$nodesToDel = array(); $nodesToDel = array();
for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) { for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
usleep(10); usleep(10);
if (!$this->isStarted()) {
break;
}
if ($n->getAttribute('temperature') == 'hot') { if ($n->getAttribute('temperature') == 'hot') {
// do not move hotfiles // do not move hotfiles
continue; continue;
@@ -557,9 +568,13 @@ class ArchiveJob extends AbstractJob
} }
$nodesToDel = array(); $nodesToDel = array();
for ($n = $node->firstChild; $this->isStarted() && $n; $n = $n->nextSibling) { for ($n = $node->firstChild; $n; $n = $n->nextSibling) {
usleep(10); usleep(10);
if (!$this->isStarted()) {
break;
}
if ($n->getAttribute('temperature') == 'hot') { if ($n->getAttribute('temperature') == 'hot') {
continue; 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) private function archiveFilesToGrp(Application $app, \databox $databox, \DOMDocument $dom, \DOMElement $node, $path, $path_archived, $path_error, $grp_rid, $stat0, $stat1, $moveError, $moveArchived)
{ {
$nodesToDel = array(); $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') { if ($n->getAttribute('isdir') == '1') {
// in a grp, all levels goes in the same grp // in a grp, all levels goes in the same grp
$node->setAttribute('archived', '1'); // the main grp folder is 'keep'ed, but not subfolders $node->setAttribute('archived', '1'); // the main grp folder is 'keep'ed, but not subfolders

View File

@@ -255,10 +255,6 @@ class RecordMoverJob extends AbstractJob
$tw[] = $tws[0]; $tw[] = $tws[0];
elseif (count($tws) > 1) elseif (count($tws) > 1)
$tw[] = '(' . implode(') OR (', $tws) . ')'; $tw[] = '(' . implode(') OR (', $tws) . ')';
if (count($tw) == 1)
$where = $tw[0];
if (count($tw) > 1)
$where = '(' . implode(') AND (', $tw) . ')';
// build the TEST sql (select) // build the TEST sql (select)
$sql_test = 'SELECT record_id FROM record' . $join; $sql_test = 'SELECT record_id FROM record' . $join;
@@ -433,13 +429,6 @@ class RecordMoverJob extends AbstractJob
$tw[] = '(status&0b' . $ma . ")=0"; $tw[] = '(status&0b' . $ma . ")=0";
} }
if (count($tw) == 1) {
$where = $tw[0];
}
if (count($tw) > 1) {
$where = '(' . implode(') AND (', $tw) . ')';
}
return array($tw, $join); return array($tw, $join);
} }
} }

View File

@@ -9,15 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
/** class patchthesaurus_100 implements patchthesaurus_interface
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class patchthesaurus_100
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode)
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas)
{ {
if ($version == "") { if ($version == "") {
$th = $domth->documentElement; $th = $domth->documentElement;
@@ -37,7 +31,7 @@ class patchthesaurus_100
} }
foreach ($te1 as $tei) { foreach ($te1 as $tei) {
$th->appendChild($tei); $th->appendChild($tei);
$this->fixThesaurus2($domth, $tei); $this->fixThesaurus2($domth, $tei, 0, $unicode);
// $tei->parentNode->removeChild($tei); // $tei->parentNode->removeChild($tei);
} }
$te0->parentNode->removeChild($te0); $te0->parentNode->removeChild($te0);
@@ -52,9 +46,8 @@ class patchthesaurus_100
return($version); 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 = $tenode->appendChild($domth->createElement("sy"));
$sy->setAttribute("lng", $v = $tenode->getAttribute("lng")); $sy->setAttribute("lng", $v = $tenode->getAttribute("lng"));
$sy->setAttribute("v", $v = $tenode->getAttribute("v")); $sy->setAttribute("v", $v = $tenode->getAttribute("v"));
@@ -73,7 +66,7 @@ class patchthesaurus_100
if ($n->nodeName == "ta") if ($n->nodeName == "ta")
$todel[] = $n; $todel[] = $n;
if ($n->nodeName == "te") if ($n->nodeName == "te")
$this->fixThesaurus2($domth, $n, $depth + 1); $this->fixThesaurus2($domth, $n, $depth + 1, $unicode);
} }
foreach ($todel as $n) { foreach ($todel as $n) {
$n->parentNode->removeChild($n); $n->parentNode->removeChild($n);

View File

@@ -9,15 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
/** class patchthesaurus_200 implements patchthesaurus_interface
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class patchthesaurus_200
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode)
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas)
{ {
if ($version == "2.0.0") { if ($version == "2.0.0") {
$th = $domth->documentElement; $th = $domth->documentElement;

View File

@@ -9,15 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
/** class patchthesaurus_201 implements patchthesaurus_interface
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class patchthesaurus_201
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode)
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas)
{ {
if ($version == "2.0.1") { if ($version == "2.0.1") {
$th = $domth->documentElement; $th = $domth->documentElement;

View File

@@ -9,15 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
/** class patchthesaurus_202 implements patchthesaurus_interface
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class patchthesaurus_202
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode)
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas)
{ {
if ($version == "2.0.2") { if ($version == "2.0.2") {
$th = $domth->documentElement; $th = $domth->documentElement;

View File

@@ -9,18 +9,11 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
/** class patchthesaurus_203 implements patchthesaurus_interface
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class patchthesaurus_203
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode)
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas)
{ {
global $ctchanged, $thchanged, $needreindex; $needreindex = false;
$unicode = new unicode();
if ($version == "2.0.3") { if ($version == "2.0.3") {
$xp = new DOMXPath($domth); $xp = new DOMXPath($domth);
@@ -46,8 +39,6 @@ class patchthesaurus_203
$domth->documentElement->setAttribute("version", "2.0.4"); $domth->documentElement->setAttribute("version", "2.0.4");
$domth->documentElement->setAttribute("modification_date", date("YmdHis")); $domth->documentElement->setAttribute("modification_date", date("YmdHis"));
$thchanged = true;
if ($needreindex) { if ($needreindex) {
print("// need to reindex, deleting cterms (keeping rejected)\n"); 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("version", "2.0.4");
$domct->documentElement->setAttribute("modification_date", date("YmdHis")); $domct->documentElement->setAttribute("modification_date", date("YmdHis"));
$ctchanged = true;
$version = "2.0.4"; $version = "2.0.4";
} }

View File

@@ -9,19 +9,12 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
/** class patchthesaurus_204 implements patchthesaurus_interface
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class patchthesaurus_204
{ {
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode)
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas)
{ {
global $ctchanged, $thchanged, $needreindex; $needreindex = false;
$unicode = new unicode();
if ($version == "2.0.4") { if ($version == "2.0.4") {
$xp = new DOMXPath($domth); $xp = new DOMXPath($domth);
$sy = $xp->query("//sy"); $sy = $xp->query("//sy");
@@ -46,8 +39,6 @@ class patchthesaurus_204
$domth->documentElement->setAttribute("version", "2.0.5"); $domth->documentElement->setAttribute("version", "2.0.5");
$domth->documentElement->setAttribute("modification_date", date("YmdHis")); $domth->documentElement->setAttribute("modification_date", date("YmdHis"));
$thchanged = true;
if ($needreindex) { if ($needreindex) {
print("// need to reindex, deleting cterms (keeping rejected)\n"); 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("version", "2.0.5");
$domct->documentElement->setAttribute("modification_date", date("YmdHis")); $domct->documentElement->setAttribute("modification_date", date("YmdHis"));
$ctchanged = true;
$version = "2.0.5"; $version = "2.0.5";
} }

View File

@@ -0,0 +1,15 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
interface patchthesaurus_interface
{
public function patch($version, \DOMDocument $domct, \DOMDocument $domth, \connection_interface $connbas, \unicode $unicode);
}

View File

@@ -1586,8 +1586,9 @@ class unicode
$out = ''; $out = '';
$_map = &self::$map[$target]; // faster in loop $_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)) { if (true === array_key_exists(($c = mb_substr($string, $i, 1, 'UTF-8')), $_map)) {
$out .= $_map[$c]; $out .= $_map[$c];
} else { } else {