From 7b0da9690c5e704dbe40a8fe16d23ff4fdb3c04e Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 17 Dec 2013 14:39:35 +0100 Subject: [PATCH 1/8] Fix #1619 Upgrade migration, checks if sbas exists before getting connection --- lib/classes/databox.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/classes/databox.php b/lib/classes/databox.php index ae22fafc82..062b5e5171 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -110,15 +110,16 @@ class databox extends base assert($sbas_id > 0); $this->app = $app; - $this->connection = connection::getPDOConnection($app, $sbas_id); $this->id = $sbas_id; $connection_params = phrasea::sbas_params($this->app); - if ( ! isset($connection_params[$sbas_id])) { + if (! isset($connection_params[$sbas_id])) { throw new NotFoundHttpException(sprintf('databox %d not found', $sbas_id)); } + $this->connection = connection::getPDOConnection($app, $sbas_id); + $this->host = $connection_params[$sbas_id]['host']; $this->port = $connection_params[$sbas_id]['port']; $this->user = $connection_params[$sbas_id]['user']; From 7f1e1d88cbea76e97b2d079f4d313b925a0a11b0 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 17 Dec 2013 20:07:19 +0100 Subject: [PATCH 2/8] Fix PHP notice when migrating from 3.6 to 3.8 --- .../Setup/Version/Migration/Migration38.php | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php b/lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php index a7725e951c..a2d6d3feab 100644 --- a/lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php +++ b/lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Setup\Version\Migration; use Alchemy\Phrasea\Application; use Symfony\Component\Yaml\Yaml; +use Alchemy\Phrasea\Exception\RuntimeException; class Migration38 implements MigrationInterface { @@ -59,10 +60,10 @@ class Migration38 implements MigrationInterface $app['phraseanet.configuration']->setConfig($conf); foreach (array( - $this->configYaml, - $this->connexionsYaml, - $this->binariesYaml, - $this->servicesYaml + $this->configYaml, + $this->connexionsYaml, + $this->binariesYaml, + $this->servicesYaml ) as $file) { if (is_file($file)) { rename($file, $file.'.bkp'); @@ -86,7 +87,8 @@ class Migration38 implements MigrationInterface if (is_file($this->configYaml)) { $data = $this->yaml->parse($this->configYaml); - $conf['main']['key'] = $data['key']; + $key = isset($data['key']) ? $data['key'] : $this->fetchInstanceKey(); + $conf['main']['key'] = $key; $env = $data['environment']; if (isset($data[$env])) { $conf['main']['servername'] = $data[$env]['phraseanet']['servername']; @@ -114,7 +116,9 @@ class Migration38 implements MigrationInterface $conf['main']['cache']['options'] = array(); } } - $conf['border-manager'] = $services['Border']['border_manager']['options']; + if (isset($services['Border'])) { + $conf['border-manager'] = $services['Border']['border_manager']['options']; + } } } @@ -127,4 +131,18 @@ class Migration38 implements MigrationInterface $conf['main']['database-test'] = $data['test_connexion']; } } + + private function fetchInstanceKey() + { + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare('SELECT `value` FROM registry WHERE `key` = "GV_SIT"'); + $stmt->execute(); + $rs = $stmt->fetch(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + if (!$rs) { + throw new RuntimeException('Unable to fetch GV_SIT key from registry table.'); + } + + return $rs['key']; + } } From ccec86c695af58b67c0806908fd78b839dbd33d8 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 18 Dec 2013 19:17:53 +0100 Subject: [PATCH 3/8] Fix namespace use --- lib/Alchemy/Phrasea/Setup/Requirements/LocalesRequirements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Setup/Requirements/LocalesRequirements.php b/lib/Alchemy/Phrasea/Setup/Requirements/LocalesRequirements.php index 73fa124c32..98d620441e 100644 --- a/lib/Alchemy/Phrasea/Setup/Requirements/LocalesRequirements.php +++ b/lib/Alchemy/Phrasea/Setup/Requirements/LocalesRequirements.php @@ -52,7 +52,7 @@ class LocalesRequirements extends RequirementCollection implements RequirementIn if (defined('INTL_ICU_VERSION')) { $version = INTL_ICU_VERSION; } else { - $reflector = new ReflectionExtension('intl'); + $reflector = new \ReflectionExtension('intl'); ob_start(); $reflector->info(); From 3f54fb3f20ce58bc02745da9563382e90c52fa8f Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 17 Dec 2013 13:42:42 +0100 Subject: [PATCH 4/8] Fix #1630 : Fix user registration management --- .../Phrasea/Controller/Admin/Users.php | 23 ++++---- .../Phrasea/Controller/Admin/UsersTest.php | 53 +++++++++++++++++++ tests/classes/PDOMock.php | 25 +++++++++ tests/classes/PhraseanetPHPUnitAbstract.php | 5 ++ 4 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 tests/classes/PDOMock.php diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index efa0131990..cee6b6544f 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -16,6 +16,8 @@ use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Alchemy\Phrasea\Notification\Receiver; +use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate; /** * @@ -546,31 +548,30 @@ class Users implements ControllerProviderInterface $row = $stmt->fetch(\PDO::FETCH_ASSOC); $stmt->closeCursor(); - $accept = $deny = ''; + $acceptColl = $denyColl = []; if ($row) { - if (\Swift_Validate::email($row['usr_mail'])) { foreach ($bases as $bas => $isok) { if ($isok) { - $accept .= '
  • ' . \phrasea::bas_labels($bas, $app) . "
  • \n"; + $acceptColl[] = \phrasea::bas_labels($bas, $app); } else { - $deny .= '
  • ' . \phrasea::bas_labels($bas, $app) . "
  • \n"; + $denyColl[] = \phrasea::bas_labels($bas, $app); } } - if (($accept != '' || $deny != '')) { + if (0 !== count($acceptColl) || 0 !== count($denyColl)) { $message = ''; - if ($accept != '') { - $message .= "\n" . _('login::register:email: Vous avez ete accepte sur les collections suivantes : ') . implode(', ', $accept). "\n"; + if (0 !== count($acceptColl)) { + $message .= "\n" . _('login::register:email: Vous avez ete accepte sur les collections suivantes : ') . implode(', ', $acceptColl). "\n"; } - if ($deny != '') { - $message .= "\n" . _('login::register:email: Vous avez ete refuse sur les collections suivantes : ') . implode(', ', $deny) . "\n"; + if (0 !== count($denyColl)) { + $message .= "\n" . _('login::register:email: Vous avez ete refuse sur les collections suivantes : ') . implode(', ', $denyColl) . "\n"; } $receiver = new Receiver(null, $row['usr_mail']); - $mail = MailSuccessEmailUpdate::create($this->app, $receiver, null, $message); + $mail = MailSuccessEmailUpdate::create($app, $receiver, null, $message); - $this->app['notification.deliverer']->deliver($mail); + $app['notification.deliverer']->deliver($mail); } } } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php index 5b4ea7abfc..9d6c52c3f7 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php @@ -408,6 +408,59 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue(self::$DI['client']->getResponse()->isOk()); } + public function testPostDemands() + { + $id = self::$DI['user_alt1']->get_id(); + $baseId = self::$DI['collection']->get_base_id(); + $param = sprintf('%s_%s', $id, $baseId); + + $appbox = self::$DI['app']['phraseanet.appbox']; + + $stmt = $this->getMockBuilder('\mysqli_stmt') + ->setMethods(['fetch']) + ->disableOriginalConstructor() + ->getMock(); + + $stmt->expects($this->any()) + ->method('fetch') + ->will($this->returnValue([ + 'usr_id' => $id, + 'base_id' => $baseId, + 'en_cours' => 1, + 'refuser' => 0, + ])); + + $pdo = $this->getMockBuilder('PDOMock') + ->setMethods(['prepare']) + ->getMock(); + + $pdo->expects($this->any()) + ->method('get_connection') + ->will($this->returnValue($stmt)); + + $appbox = $this->getMockBuilder('\appbox') + ->setMethods(['get_connection']) + ->disableOriginalConstructor() + ->getMock(); + + $appbox->expects($this->any()) + ->method('get_connection') + ->will($this->returnValue($pdo)); + + $this->mockNotificationDeliverer('Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate'); + + self::$DI['client']->request('POST', '/admin/users/demands/', [ + 'template' => [], + 'accept' => [$param], + 'accept_hd' => [$param], + 'watermark' => [$param], + ]); + + self::$DI['app']['phraseanet.appbox'] = $appbox; + + $this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); + } + public function testRenderImportFile() { self::$DI['client']->request('GET', '/admin/users/import/file/'); diff --git a/tests/classes/PDOMock.php b/tests/classes/PDOMock.php new file mode 100644 index 0000000000..698319d844 --- /dev/null +++ b/tests/classes/PDOMock.php @@ -0,0 +1,25 @@ +getMock('PDOMock') + */ +class PDOMock extends \PDO +{ + public function __construct() {} +} \ No newline at end of file diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index bfbd6f5d73..749ac916ec 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -1001,3 +1001,8 @@ class CsrfTestProvider implements CsrfProviderInterface return true; } } + +class PDOMock extends \PDO +{ + public function __construct() {} +} From 529f09e93e609cd9921d71edebe780ad3de34f2a Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 17 Dec 2013 20:28:23 +0100 Subject: [PATCH 5/8] Move CSRFTestProvider class to a PSR 0 compatible file --- tests/classes/CrsfTestProvider.php | 25 +++++++++++++++++++++ tests/classes/PhraseanetPHPUnitAbstract.php | 18 --------------- 2 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 tests/classes/CrsfTestProvider.php diff --git a/tests/classes/CrsfTestProvider.php b/tests/classes/CrsfTestProvider.php new file mode 100644 index 0000000000..689cb7726f --- /dev/null +++ b/tests/classes/CrsfTestProvider.php @@ -0,0 +1,25 @@ +getMock(); } } - -class CsrfTestProvider implements CsrfProviderInterface -{ - public function generateCsrfToken($intention) - { - return mt_rand(); - } - - public function isCsrfTokenValid($intention, $token) - { - return true; - } -} - -class PDOMock extends \PDO -{ - public function __construct() {} -} From 7c156f42c8e5aff8f6dfcabc4557eeca6c7ac163 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 18 Dec 2013 11:37:54 +0100 Subject: [PATCH 6/8] Fix neutron comments --- .../Phrasea/Controller/Admin/UsersTest.php | 13 +++------- tests/classes/CrsfTestProvider.php | 25 ------------------- tests/classes/CsrfTestProvider.php | 19 ++++++++++++++ tests/classes/PDOMock.php | 10 +------- tests/classes/unitTestsTest.php | 2 ++ 5 files changed, 26 insertions(+), 43 deletions(-) delete mode 100644 tests/classes/CrsfTestProvider.php create mode 100644 tests/classes/CsrfTestProvider.php diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php index 9d6c52c3f7..c1c6bd4433 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/UsersTest.php @@ -416,13 +416,10 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $appbox = self::$DI['app']['phraseanet.appbox']; - $stmt = $this->getMockBuilder('\mysqli_stmt') - ->setMethods(['fetch']) - ->disableOriginalConstructor() - ->getMock(); + $stmt = $this->getMock('PDOStatement'); $stmt->expects($this->any()) - ->method('fetch') + ->method('fetchAll') ->will($this->returnValue([ 'usr_id' => $id, 'base_id' => $baseId, @@ -430,12 +427,10 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract 'refuser' => 0, ])); - $pdo = $this->getMockBuilder('PDOMock') - ->setMethods(['prepare']) - ->getMock(); + $pdo = $this->getMock('PDOMock'); $pdo->expects($this->any()) - ->method('get_connection') + ->method('prepare') ->will($this->returnValue($stmt)); $appbox = $this->getMockBuilder('\appbox') diff --git a/tests/classes/CrsfTestProvider.php b/tests/classes/CrsfTestProvider.php deleted file mode 100644 index 689cb7726f..0000000000 --- a/tests/classes/CrsfTestProvider.php +++ /dev/null @@ -1,25 +0,0 @@ - Date: Wed, 18 Dec 2013 23:35:42 +0100 Subject: [PATCH 7/8] Fix autoregister --- lib/classes/eventsmanager/notify/autoregister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/classes/eventsmanager/notify/autoregister.php b/lib/classes/eventsmanager/notify/autoregister.php index 20120a5302..ca0e85caea 100644 --- a/lib/classes/eventsmanager/notify/autoregister.php +++ b/lib/classes/eventsmanager/notify/autoregister.php @@ -206,7 +206,7 @@ class eventsmanager_notify_autoregister extends eventsmanager_notifyAbstract } if ($readyToSend) { - $mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, $body); + $mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, null, $body); $this->app['notification.deliverer']->deliver($mail); } From 1d9a0674189cf93899595e9c871fb568efe45c01 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 19 Dec 2013 00:35:20 +0100 Subject: [PATCH 8/8] Fix highlight --- lib/Alchemy/Phrasea/Application.php | 4 ++-- templates/web/prod/results/record.html.twig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index e7ad5c7c15..12bcda016f 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -617,7 +617,7 @@ class Application extends SilexApplication })); $twig->addFilter(new \Twig_SimpleFilter('thesaurus', function (\Twig_Environment $twig, $value) { if (!$value instanceof \ThesaurusValue) { - return twig_escape_filter($twig, str_replace(array('[[em]]', '[[/em]]'), array('', ''), $value)); + return str_replace(array('[[em]]', '[[/em]]'), array('', ''), twig_escape_filter($twig, $value)); } return "getField()->get_databox()->get_sbas_id() . "','" @@ -625,7 +625,7 @@ class Application extends SilexApplication . "', '" . str_replace("'", "\\'", $value->getField()->get_name()) . "');return(false);\">" - . twig_escape_filter($twig, str_replace(array('[[em]]', '[[/em]]'), array('', ''), $value->getValue())) + . str_replace(array('[[em]]', '[[/em]]'), array('', ''), twig_escape_filter($twig, $value->getValue())) . ""; }, array('needs_environment' => true, 'is_safe' => array('html')))); diff --git a/templates/web/prod/results/record.html.twig b/templates/web/prod/results/record.html.twig index d47585d21a..ce05fac0d8 100644 --- a/templates/web/prod/results/record.html.twig +++ b/templates/web/prod/results/record.html.twig @@ -23,7 +23,7 @@
    - {{record.get_title(highlight, searchEngine)|raw}} + {{record.get_title(highlight, searchEngine)|thesaurus}}
    {{record.get_status_icons|raw}}