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/stamp
/config/configuration.yml
.DS_Store
/vendor
/plugins
/node_modules

View File

@@ -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.');

View File

@@ -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;

View File

@@ -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');

View File

@@ -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');
}

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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";
}

View File

@@ -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";
}

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 = '';
$_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 {