From caff1bce62177bfcfc564c306d0ee933694c44d1 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 4 Jan 2012 14:36:15 +0100 Subject: [PATCH 1/6] add config file upgrade process --- lib/Alchemy/Phrasea/Application/Setup.php | 41 +++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/Application/Setup.php b/lib/Alchemy/Phrasea/Application/Setup.php index be6c0d7f68..03b89545de 100644 --- a/lib/Alchemy/Phrasea/Application/Setup.php +++ b/lib/Alchemy/Phrasea/Application/Setup.php @@ -22,11 +22,10 @@ require_once __DIR__ . '/../../../bootstrap.php'; * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ - return call_user_func(function() { $app = new Silex\Application(); - + $app['Core'] = bootstrap::getCore(); $app['install'] = false; @@ -39,10 +38,48 @@ return call_user_func(function() $appbox = appbox::get_instance(); if (!$appbox->need_major_upgrade()) + { throw new Exception_Setup_PhraseaAlreadyInstalled(); + } $app['upgrade'] = true; } + elseif (\setup::needUpgradeConfigurationFile()) + { + //copy sample + $file = __DIR__ . "/../../../../config/config.sample.yml"; + $file1 = __DIR__ . "/../../../../config/config.yml"; + if (!copy($file, $file1)) + { + throw new \Exception(sprintf("Unable to copy %s", $file1)); + } + + //get connexion credentials + $conn = \connection::getPDOConnection(); + $credentials = $conn->get_credentials(); + + //get configuration object + $app = new \Alchemy\Phrasea\Core\Configuration\Application(); + $parser = new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml(); + $handler = new \Alchemy\Phrasea\Core\Configuration\Handler($app, $parser); + $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); + + //refactor credentials + $connexionINI = array(); + foreach ($credentials as $key => $value) + { + $key = $key == 'hostname' ? 'host' : $key; + $connexionINI[$key] = (string) $value; + } + //write credentials to config file + $configuration->setAllDatabaseConnexion($connexionINI); + $request = $app["request"]; + //write servername + $serverName = $request->getScheme() . '://' . $request->getHttpHost() . '/'; + $configuration->setServerName($serverName); + + $app->redirect("/"); + } else { $app['install'] = true; From 403fa93fd7ba5e59d6c06a25738b6d687cd9215d Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 4 Jan 2012 14:38:14 +0100 Subject: [PATCH 2/6] add doctrine schema creation on install process --- .../Phrasea/Controller/Setup/Installer.php | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index d7bbff1eed..1996d00da7 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -170,16 +170,29 @@ class Installer implements ControllerProviderInterface try { - $servername = $request->getScheme() . '://' . $request->getHttpHost() . '/'; - $setupRegistry = new \Setup_Registry(); - $setupRegistry->set('GV_ServerName', $servername); - $appbox = \appbox::create($setupRegistry, $conn, $appbox_name, true); + $servername = $request->getScheme() . '://' . $request->getHttpHost() . '/'; + $setupRegistry = new \Setup_Registry(); + $setupRegistry->set('GV_ServerName', $servername); + $appbox = \appbox::create($setupRegistry, $conn, $appbox_name, true); + + $em = $app['Core']->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + + $metadatas = $em->getMetadataFactory()->getAllMetadata(); + + if (!empty($metadatas)) + { + // Create SchemaTool + $tool = new \Doctrine\ORM\Tools\SchemaTool($em); + // Create schema + $schemaTool->createSchema($metadatas); + } $registry = \registry::get_instance(); \setup::create_global_values($registry); $appbox->set_registry($registry); - + $registry->set('GV_base_datapath_noweb', \p4string::addEndSlash($request->get('datapath_noweb'))); $registry->set('GV_base_datapath_web', \p4string::addEndSlash($request->get('datapath_web'))); $registry->set('GV_base_dataurl', \p4string::addEndSlash($request->get('mount_point_web'))); From e902fa9728a35f0fd21bd6020b4c7c750d17136a Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 4 Jan 2012 14:38:58 +0100 Subject: [PATCH 3/6] add setup::needUpgradeConfigurationFile methode --- lib/classes/setup.class.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/classes/setup.class.php b/lib/classes/setup.class.php index c34026e6cc..3a22c14349 100644 --- a/lib/classes/setup.class.php +++ b/lib/classes/setup.class.php @@ -69,10 +69,16 @@ class setup public static function is_installed() { $appConf = new \Alchemy\Phrasea\Core\Configuration\Application(); - + return is_file($appConf->getConfigurationPathName()); } - + + public static function needUpgradeConfigurationFile() + { + return (is_file(__DIR__ . "/../../conf/connexion.inc") + && is_file(__DIR__ . "/../../config.inc")); + } + function create_global_values(registryInterface &$registry, $datas=array()) { require(__DIR__ . "/../../lib/conf.d/_GV_template.inc"); From 52b3f8a2a877dbec621504c4204461a863d5b08c Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 4 Jan 2012 14:40:10 +0100 Subject: [PATCH 4/6] replace bas_manage to manage for user's rights --- lib/unitTest/PhraseanetPHPUnitAbstract.class.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc index 2dda134831..fa3229c10a 100644 --- a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc +++ b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc @@ -452,7 +452,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase , 'imgtools' => '1' , 'manage' => '1' , 'modify_struct' => '1' - , 'bas_manage' => '1' + , 'manage' => '1' , 'bas_modify_struct' => '1' ); From 06f539e7d56d6ac04e157418de9773bee5939267 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 4 Jan 2012 16:54:23 +0100 Subject: [PATCH 5/6] fix install with no databox & trans string --- templates/web/setup/step2.twig | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/templates/web/setup/step2.twig b/templates/web/setup/step2.twig index 52f687456b..1fdf08b240 100644 --- a/templates/web/setup/step2.twig +++ b/templates/web/setup/step2.twig @@ -9,6 +9,7 @@ var $this = $(this); var $current = $this.closest('.steps'); $('.databox_creation_input', $current).attr('disabled', $this.attr('checked')); + $('.db_tester', $current).attr('disabled', $this.attr('checked')).toggleClass( "ui-state-disabled", $this.attr('checked') ); }); $('.ab_opt_toggler').bind('click', function(){ $('.optional_ab_datas').fadeToggle(); @@ -121,12 +122,12 @@ setTimeout("$('form#create_admin').submit();",500); }; } - + if($current.hasClass('appbox_settings')) { test_connection_appbox(callback); } - else if($current.hasClass('databox_settings')) + else if($current.hasClass('databox_settings') && $('.databox_create', $current).is(':not(:checked)')) { test_connection_databox(callback); } @@ -194,7 +195,7 @@ var password_input = $('input[name="ab_password"]', appbox_scope); var dbname_input = $('input[name="db_name"]', databox_scope); - + var user = user_input.val(); var password = password_input.val(); var dbname = dbname_input.val(); @@ -236,10 +237,10 @@ if(datas.connection === true && datas.database === true) { el_status.attr('src','/skins/icons/ok.png').show(); - el_message.empty().append('{% trans 'Successfull connection' %}'); + el_message.empty().append("{% trans 'Successfull connection' %}"); if(!datas.is_empty) { - el_message.append('
{% trans 'Warning, this database is not empty' %}'); + el_message.append("
{% trans 'Warning, this database is not empty' %}"); el_status.attr('src','/skins/icons/alert.png').show(); } if(typeof callback == 'function') @@ -249,11 +250,11 @@ } if(datas.connection === true) { - el_message.empty().append('{% trans 'Connection is OK but database does not exists or can not be accessed' %}'); + el_message.empty().append("{% trans 'Connection is OK but database does not exists or can not be accessed' %}"); } else { - el_message.empty().append('{% trans 'Unable to connect to MySQL server' %}'); + el_message.empty().append("{% trans 'Unable to connect to MySQL server' %}"); } el_status.attr('src', '/skins/icons/delete.png').show(); @@ -262,12 +263,12 @@ timeout:function(){ el_loader.css('visibility', 'hidden'); el_status.attr('src', '/skins/icons/delete.png').show(); - el_message.empty().append('{% trans 'Unable to connect to MySQL server' %}'); + el_message.empty().append("{% trans 'Unable to connect to MySQL server' %}"); }, error:function(datas){ el_loader.css('visibility', 'hidden'); el_status.attr('src', '/skins/icons/delete.png').show(); - el_message.empty().append('{% trans 'Unable to connect to MySQL server' %}'); + el_message.empty().append("{% trans 'Unable to connect to MySQL server' %}"); } }); } From c7d0d7865869d6c3c3ea83240855dab55a1b243e Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 4 Jan 2012 17:54:50 +0100 Subject: [PATCH 6/6] fix creation schema error on install --- .../Phrasea/Controller/Setup/Installer.php | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index 1996d00da7..5652909f98 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -175,17 +175,29 @@ class Installer implements ControllerProviderInterface $setupRegistry->set('GV_ServerName', $servername); $appbox = \appbox::create($setupRegistry, $conn, $appbox_name, true); - $em = $app['Core']->getEntityManager(); - /* @var $em \Doctrine\ORM\EntityManager */ - - $metadatas = $em->getMetadataFactory()->getAllMetadata(); - - if (!empty($metadatas)) + $handler = new \Alchemy\Phrasea\Core\Configuration\Handler( + new \Alchemy\Phrasea\Core\Configuration\Application(), + new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() + ); + $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); + if ($configuration->isInstalled()) { - // Create SchemaTool - $tool = new \Doctrine\ORM\Tools\SchemaTool($em); - // Create schema - $schemaTool->createSchema($metadatas); + // Get Entity Manager using the new configuration + $doctrineConf = $configuration->getDoctrine()->all(); + $doctrine = new \Alchemy\Phrasea\Core\Service\Doctrine($doctrineConf); + + $em = $doctrine->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + + $metadatas = $em->getMetadataFactory()->getAllMetadata(); + + if (!empty($metadatas)) + { + // Create SchemaTool + $tool = new \Doctrine\ORM\Tools\SchemaTool($em); + // Create schema + $tool->createSchema($metadatas); + } } $registry = \registry::get_instance();