From af9307b1484fa5d8a0a631420a41c42fa81df064 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 17 Jun 2013 22:04:01 +0200 Subject: [PATCH 1/2] Add sessions patch --- lib/Alchemy/Phrasea/Core/Version.php | 2 +- lib/classes/base.php | 4 + lib/classes/module/console/systemUpgrade.php | 21 +++- lib/classes/patch/3811.php | 116 +++++++++++++++++++ 4 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 lib/classes/patch/3811.php diff --git a/lib/Alchemy/Phrasea/Core/Version.php b/lib/Alchemy/Phrasea/Core/Version.php index dc7b55ef36..93d8287904 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.8.0.a10'; + protected static $number = '3.8.0.a11'; protected static $name = 'Carnosaurus'; public static function getNumber() diff --git a/lib/classes/base.php b/lib/classes/base.php index c43fee9a87..8b5f7b27d0 100644 --- a/lib/classes/base.php +++ b/lib/classes/base.php @@ -262,6 +262,7 @@ abstract class base implements cache_cacheableInterface $stmt->closeCursor(); $ORMTables = array( + 'AuthFailures', 'BasketElements', 'Baskets', 'StoryWZ', @@ -275,6 +276,9 @@ abstract class base implements cache_cacheableInterface 'LazaretChecks', 'LazaretFiles', 'LazaretSessions', + 'SessionModules', + 'Sessions', + 'UsrAuthProviders', ); foreach ($rs as $row) { diff --git a/lib/classes/module/console/systemUpgrade.php b/lib/classes/module/console/systemUpgrade.php index f9f9459265..f5fbfab0f5 100644 --- a/lib/classes/module/console/systemUpgrade.php +++ b/lib/classes/module/console/systemUpgrade.php @@ -30,8 +30,9 @@ class module_console_systemUpgrade extends Command $this ->setDescription('Upgrade Phraseanet to the latest version') - ->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions and do not ask the user') - ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force the upgrade even if there is a concurrent upgrade'); + ->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answers yes to all questions and do not ask the user') + ->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces the upgrade even if there is a concurrent upgrade') + ->addOption('dump', 'd', InputOption::VALUE_NONE, 'Dumps SQL queries that can be used to clean database.'); return $this; } @@ -72,7 +73,21 @@ class module_console_systemUpgrade extends Command $upgrader = new Setup_Upgrade($this->container, $input->getOption('force')); - $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container); + $queries = $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container); + + if ($input->getOption('dump')) { + if (0 < count($queries)) { + $output->writeln("Some SQL queries can be executed to optimize\n"); + + foreach ($queries as $query) { + $output->writeln(" ".$query['sql']); + } + + $output->writeln("\n"); + } else { + $output->writeln("No SQL queries to execute to optimize\n"); + } + } foreach ($upgrader->getRecommendations() as $recommendation) { list($message, $command) = $recommendation; diff --git a/lib/classes/patch/3811.php b/lib/classes/patch/3811.php new file mode 100644 index 0000000000..e8ac9a2c6f --- /dev/null +++ b/lib/classes/patch/3811.php @@ -0,0 +1,116 @@ +release; + } + + /** + * {@inheritdoc} + */ + public function require_all_upgrades() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function concern() + { + return $this->concern; + } + + /** + * {@inheritdoc} + */ + public function apply(base $appbox, Application $app) + { + try { + $sql = 'SELECT usr_id, user_agent, ip, platform, browser, app, + browser_version, screen, token, nonce, lastaccess, created_on + FROM cache'; + $stmt = $appbox->get_connection()->prepare($sql); + $stmt->execute(); + $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + } catch (\PDOException $e) { + // this may fail on oldest versions + return; + } + + foreach ($rs as $row) { + $created = $updated = null; + if ('0000-00-00 00:00:00' !== $row['created_on']) { + $created = \DateTime::createFromFormat('Y-m-d H:i:s', $row['created_on']); + } + if ('0000-00-00 00:00:00' !== $row['lastaccess']) { + $updated = \DateTime::createFromFormat('Y-m-d H:i:s', $row['lastaccess']); + } + + $session = new Session(); + $session + ->setUsrId($row['usr_id']) + ->setUserAgent($row['user_agent']) + ->setUpdated($updated) + ->setToken($row['token']) + ->setPlatform($row['platform']) + ->setNonce($row['nonce']) + ->setIpAddress($row['ip']) + ->setCreated($created) + ->setBrowserVersion($row['browser_version']) + ->setBrowserName($row['browser']); + + $sizes = explode ('x', $row['screen']); + + if (2 === count($sizes)) { + $session + ->setScreenWidth($sizes[0]) + ->setScreenHeight($sizes[1]); + } + + if (false !== $apps = @unserialize($row['app'])) { + foreach ($apps as $app) { + $module = new SessionModule(); + $module + ->setModuleId($app) + ->setCreated($created) + ->setSession($session) + ->setUpdated($updated); + + $session->addModule($module); + + $app['EM']->persist($module); + } + } + + $app['EM']->persist($session); + } + + $app['EM']->flush(); + } +} From f4c174a19b9e4fda95fc75122c55a748a42bae93 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Mon, 17 Jun 2013 22:04:27 +0200 Subject: [PATCH 2/2] Add note about database upgrade and cleanup --- UPGRADE-3.8.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/UPGRADE-3.8.md b/UPGRADE-3.8.md index 576f3e679e..f2f53ff7b4 100644 --- a/UPGRADE-3.8.md +++ b/UPGRADE-3.8.md @@ -68,6 +68,13 @@ The idea of `bin/setup` is to provide an commandline tool that is not aware of Phraseanet Installation, whereas `bin/console` requires an up-to-date Phraseanet install. +## Database Upgrade + +Database will be upgraded when running the `bin/console system:upgrade` command. +This command will not remove old tables. To remove them, use the +`--dump` option of the previous command to get a dump of the raw SQL commands to +execute; + ## Customization If you were using custom homepage or LDAP connection, they might not work.