diff --git a/lib/Alchemy/Phrasea/Controller/Client/Root.php b/lib/Alchemy/Phrasea/Controller/Client/Root.php index 18cf4f9b69..c82d32d8f5 100644 --- a/lib/Alchemy/Phrasea/Controller/Client/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Client/Root.php @@ -220,7 +220,7 @@ class Root implements ControllerProviderInterface 'per_page' => $perPage, 'search_engine' => $app['phraseanet.SE'], 'search_engine_option' => $options->serialize(), - 'history' => \queries::history($app['phraseanet.appbox'], $app['authentication']->getUser()->get_id()), + 'history' => \queries::history($app, $app['authentication']->getUser()->get_id()), 'result' => $result, 'proposals' => $currentPage === 1 ? $result->getProposals() : null, 'help' => count($resultData) === 0 ? $this->getHelpStartPage($app) : '', diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Root.php b/lib/Alchemy/Phrasea/Controller/Prod/Root.php index 3360b20e77..75d889bc39 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Root.php @@ -119,7 +119,7 @@ class Root implements ControllerProviderInterface 'GV_google_api' => $app['phraseanet.registry']->get('GV_google_api'), 'queries_topics' => $queries_topics, 'search_status' => \databox_status::getSearchStatus($app), - 'queries_history' => \queries::history($app['phraseanet.appbox'], $app['authentication']->getUser()->get_id()), + 'queries_history' => \queries::history($app, $app['authentication']->getUser()->get_id()), 'thesau_js_list' => $thjslist, 'thesau_json_sbas' => json_encode($sbas), 'thesau_json_bas2sbas' => json_encode($bas2sbas), diff --git a/lib/Alchemy/Phrasea/Core/Version.php b/lib/Alchemy/Phrasea/Core/Version.php index 2e06f34220..ffc74f47b2 100644 --- a/lib/Alchemy/Phrasea/Core/Version.php +++ b/lib/Alchemy/Phrasea/Core/Version.php @@ -18,7 +18,7 @@ namespace Alchemy\Phrasea\Core; */ class Version { - protected static $number = '3.9.0.a2'; + protected static $number = '3.9.0.a3'; protected static $name = 'Diplodocus'; public static function getNumber() diff --git a/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php index a57828a37e..d6c4ab65c7 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Phrasea/PhraseaEngine.php @@ -18,6 +18,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineResult; use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion; use Alchemy\Phrasea\Exception\RuntimeException; use Doctrine\Common\Collections\ArrayCollection; +use Entities\UserQuery; class PhraseaEngine implements SearchEngineInterface { @@ -440,7 +441,7 @@ class PhraseaEngine implements SearchEngineInterface private function getSuggestions($query) { $suggestions = array(); - + if ($this->qp && isset($this->qp['main'])) { $suggestions = array_map(function ($value) use ($query) { return new SearchEngineSuggestion($query, $value['value'], $value['hits']); @@ -575,8 +576,17 @@ class PhraseaEngine implements SearchEngineInterface $stmt->execute($params); $stmt->closeCursor(); - if ($this->app['authentication']->getUser()) { - \User_Adapter::saveQuery($this->app, $query); + if (null !== $user = $this->app['authentication']->getUser()) { + $userQuery = new UserQuery(); + $userQuery->setUsrId($user->get_id()); + $userQuery->setQuery($query); + + $this->app['EM']->persist($userQuery); + $this->app['EM']->flush(); + + if ($user->getPrefs('start_page') === 'LAST_QUERY') { + $user->setPrefs('start_page_query', $query); + } } return $this; diff --git a/lib/Doctrine/Entities/UserQuery.php b/lib/Doctrine/Entities/UserQuery.php new file mode 100644 index 0000000000..7c9232c75f --- /dev/null +++ b/lib/Doctrine/Entities/UserQuery.php @@ -0,0 +1,104 @@ +id; + } + + /** + * @return integer + */ + public function getUsrId() + { + return $this->usrId; + } + + /** + * @param integer $usrId + */ + public function setUsrId($usrId) + { + $this->usrId = $usrId; + } + + /** + * @param Application $app + * + * @return \User_Adapter + */ + public function getUser(Application $app) + { + return \User_Adapter::getInstance($this->usrId, $app); + } + + /** + * @return string + */ + public function getQuery() + { + return $this->query; + } + + /** + * @param string $query + */ + public function setQuery($query) + { + $this->query = $query; + } + + /** + * @return \DateTime + */ + public function getCreated() + { + return $this->created; + } +} diff --git a/lib/Doctrine/Repositories/UserQueryRepository.php b/lib/Doctrine/Repositories/UserQueryRepository.php new file mode 100644 index 0000000000..bbbf639550 --- /dev/null +++ b/lib/Doctrine/Repositories/UserQueryRepository.php @@ -0,0 +1,24 @@ +ACL; } - /** - * Query in the cache - * - * @param Application $app - * @param string $query - * - * @return boolean - */ - public static function saveQuery(Application $app, $query) - { - try { - $sql = "INSERT INTO dsel (id, name, usr_id, query) - VALUES (null, :name, :usr_id, :query)"; - $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); - $stmt->execute(array( - ':name' => $query, - ':usr_id' => $app['authentication']->getUser()->get_id(), - ':query' => $query - )); - $stmt->closeCursor(); - - if ($app['authentication']->getUser()->getPrefs('start_page') == 'LAST_QUERY') - $app['authentication']->getUser()->setPrefs('start_page_query', $query); - } catch (Exception $e) { - return false; - } - - return true; - } - /** * * @return string diff --git a/lib/classes/User/Interface.php b/lib/classes/User/Interface.php index 544d2651fa..fa49525f24 100644 --- a/lib/classes/User/Interface.php +++ b/lib/classes/User/Interface.php @@ -128,8 +128,6 @@ interface User_Interface public static function getInstance($id, Application $app); - public static function saveQuery(Application $app, $query); - public static function get_usr_id_from_login(Application $app, $login); public static function get_usr_id_from_email(Application $app, $email); diff --git a/lib/classes/patch/3903.php b/lib/classes/patch/3903.php new file mode 100644 index 0000000000..efce6e6a41 --- /dev/null +++ b/lib/classes/patch/3903.php @@ -0,0 +1,80 @@ +release; + } + + /** + * {@inheritdoc} + */ + public function require_all_upgrades() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function concern() + { + return $this->concern; + } + + /** + * {@inheritdoc} + */ + public function apply(base $appbox, Application $app) + { + $conn = $app['phraseanet.appbox']->get_connection(); + $sql = 'SELECT * FROM dsel'; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $n = 0; + $em = $app['EM']; + + foreach ($rs as $row) { + $userQuery = new UserQuery(); + $userQuery->setQuery($row['query']); + $userQuery->setUsrId($row['usr_id']); + + $em->persist($userQuery); + + $n++; + + if ($n % 1000 === 0) { + $em->flush(); + $em->clear(); + } + } + + $em->flush(); + $em->clear(); + } +} diff --git a/lib/classes/queries.php b/lib/classes/queries.php index 733b5ca85a..60ea1527ab 100644 --- a/lib/classes/queries.php +++ b/lib/classes/queries.php @@ -9,15 +9,10 @@ * file that was distributed with this source code. */ -/** - * - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ +use Alchemy\Phrasea\Application; + class queries { - public static function tree_topics($I18N) { $out = ''; @@ -188,22 +183,16 @@ class queries return $out; } - public static function history(appbox $appbox, $usr_id) + public static function history(Application $app, $usrId) { - $conn = $appbox->get_connection(); - - $sql = "SELECT query from dsel where usr_id = :usr_id - ORDER BY id DESC LIMIT 0,25"; - - $stmt = $conn->prepare($sql); - $stmt->execute(array(':usr_id' => $usr_id)); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - $history = '