From d14d91abaf97d5b2aa29c1b7abdffbc608bc2814 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Sun, 4 May 2014 13:14:57 +0200 Subject: [PATCH] Fixing boot up process see #7124 --- config/configuration.dist.php | 2 +- main/inc/lib/api.lib.php | 2 +- main/install/index.php | 32 +++++----- main/install/install.lib.php | 2 +- .../Command/Template/AsseticDumpCommand.php | 4 +- src/ChamiloLMS/Framework/Application.php | 61 ++++++++++++++++++- src/ChamiloLMS/Resources/config/prod.php | 6 +- src/ChamiloLMS/app.php | 54 +--------------- src/ChamiloLMS/paths.php | 21 +++++++ src/ChamiloLMS/services.php | 2 +- 10 files changed, 109 insertions(+), 77 deletions(-) create mode 100644 src/ChamiloLMS/paths.php diff --git a/config/configuration.dist.php b/config/configuration.dist.php index 141d66a0eb..26df2b7ba2 100644 --- a/config/configuration.dist.php +++ b/config/configuration.dist.php @@ -54,7 +54,7 @@ $_configuration['main_database'] = '{DATABASE_MAIN}'; //$_configuration['path.courses'] = null; // Path to the logs folder, example /var/www/chamilo/logs -//$_configuration['path.log'] = null; +//$_configuration['path.logs'] = null; /** * diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index d9fa7eb9d5..21b4d2e3ad 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -658,7 +658,7 @@ function api_get_path($path_type, $path = null) { // Update data path to get it from config file if defined $paths[SYS_DATA_PATH] = $app['path.data']; - $paths[SYS_LOG_PATH] = $app['path.log']; + $paths[SYS_LOG_PATH] = $app['path.logs']; $paths[SYS_CONFIG_PATH] = $app['path.config']; $paths[SYS_COURSE_PATH] = $app['path.courses']; diff --git a/main/install/index.php b/main/install/index.php index fafc04424c..20346e53a8 100644 --- a/main/install/index.php +++ b/main/install/index.php @@ -1,5 +1,6 @@ bindInstallPaths(require $app['path.app'].'paths.php'); +$app->readConfigurationFiles(); + +$app['path.data'] = isset($_configuration['path.data']) ? $_configuration['path.data'] : $app['path.data']; +$app['path.courses'] = isset($_configuration['path.courses']) ? $_configuration['path.courses'] : $app['path.courses']; +$app['path.logs'] = isset($_configuration['path.logs']) ? $_configuration['path.logs'] : $app['path.logs']; +$app['path.temp'] = isset($_configuration['path.temp']) ? $_configuration['path.temp'] : $app['path.temp']; + // Registering services $app['debug'] = true; @@ -124,10 +131,7 @@ foreach ($helpers as $name => $helper) { } $blockInstallation = function () use ($app) { - - if (file_exists($app['root_sys'].'config/configuration.php') || - file_exists($app['root_sys'].'config/configuration.yml') - ) { + if (file_exists($app['path.config'].'configuration.php')) { return $app->abort(500, "A Chamilo installation was found. You can't reinstall."); } @@ -485,13 +489,13 @@ $app->get('/finish', function () use ($app) { $output = $app['session']->get('output'); $message = $app['translator']->trans( 'To protect your site, make the whole %s directory read-only (chmod 0555 on Unix/Linux)', - array('%s' => $app['root_sys'].'config') + array('%s' => $app['path.config']) ); $app['session']->getFlashBag()->add('warning', $message); $message = $app['translator']->trans( 'Delete the %s directory.', - array('%s' => $app['root_sys'].'install') + array('%s' => $app['path.base'].'install') ); $app['session']->getFlashBag()->add('warning', $message); diff --git a/main/install/install.lib.php b/main/install/install.lib.php index 8aa2352f8d..0461d438c4 100755 --- a/main/install/install.lib.php +++ b/main/install/install.lib.php @@ -302,7 +302,7 @@ function drawPermissionsSettings($app) $html .= '
'; $course_attempt_name = '__XxTestxX__'; - $course_dir = $app['sys_course_path'].$course_attempt_name; + $course_dir = $app['path.courses'].$course_attempt_name; // Just in case. if (is_file($course_dir.'/test.txt')) { diff --git a/src/ChamiloLMS/Command/Template/AsseticDumpCommand.php b/src/ChamiloLMS/Command/Template/AsseticDumpCommand.php index 7298166adf..db76dc8e75 100644 --- a/src/ChamiloLMS/Command/Template/AsseticDumpCommand.php +++ b/src/ChamiloLMS/Command/Template/AsseticDumpCommand.php @@ -68,7 +68,7 @@ class AsseticDumpCommand extends Command } foreach ($themes as $theme) { - if (is_dir($app['root_sys'].'main/css/'.$theme) && file_exists($app['root_sys'].'main/css/'.$theme.'/default.css')) { + if (is_dir($app['path.base'].'main/css/'.$theme) && file_exists($app['path.base'].'main/css/'.$theme.'/default.css')) { $output->writeln("Dumping theme: $theme"); /** @var \SilexAssetic\Assetic\Dumper $dumper */ @@ -77,7 +77,7 @@ class AsseticDumpCommand extends Command $app['assetic.output.path_to_css'] = 'css/'.$theme.'/style.css'; $params = array( - $app['root_sys'].'main/css/'.$theme => $app['assetic.input.path_to_assets'].'/css/'.$theme + $app['path.base'].'main/css/'.$theme => $app['assetic.input.path_to_assets'].'/css/'.$theme ); $app['chamilo.filesystem']->copyFolders($params, $output); diff --git a/src/ChamiloLMS/Framework/Application.php b/src/ChamiloLMS/Framework/Application.php index 6e373c7ac5..42ae29b415 100644 --- a/src/ChamiloLMS/Framework/Application.php +++ b/src/ChamiloLMS/Framework/Application.php @@ -3,7 +3,7 @@ namespace ChamiloLMS\Framework; -use Zend\Config; +use Zend\Config\Config; /** * Class Application @@ -41,6 +41,9 @@ class Application extends \Silex\Application return $this->configurationArray; } + /** + * @return Config + */ public function getConfiguration() { return $this->configuration; @@ -64,7 +67,7 @@ class Application extends \Silex\Application $this->configuration = $this->getConfigurationArrayFromFile(); if (!empty($this->configuration)) { - $config = new \Zend\Config\Config($this->configuration, true); + $config = new Config($this->configuration, true); $this->installed = true; /** Overwriting paths */ @@ -72,7 +75,7 @@ class Application extends \Silex\Application $this['path.data'] = empty($config->get('path.data')) ? $this['path.data'] : $config->get('path.data'); $this['path.course'] = empty($config->get('path.courses')) ? $this['path.courses'] : $config->get('path.courses'); $this['path.temp'] = empty($config->get('path.temp')) ? $this['path.temp'] : $config->get('path.temp'); - $this['path.log'] = empty($config->get('path.log')) ? $this['path.log'] : $config->get('path.log'); + $this['path.logs'] = empty($config->get('path.logs')) ? $this['path.logs'] : $config->get('path.logs'); $configPath = $this['path.config']; @@ -112,4 +115,56 @@ class Application extends \Silex\Application $this->configuration = $config; } } + + public function setupDoctrineExtensions() + { + if (isset($this->getConfiguration()->main_database) && isset($this['db.event_manager'])) { + + // @todo improvement do not create every time this objects + $sortableGroup = new \Gedmo\Mapping\Annotation\SortableGroup(array()); + $sortablePosition = new \Gedmo\Mapping\Annotation\SortablePosition(array()); + $tree = new \Gedmo\Mapping\Annotation\Tree(array()); + $tree = new \Gedmo\Mapping\Annotation\TreeParent(array()); + $tree = new \Gedmo\Mapping\Annotation\TreeLeft(array()); + $tree = new \Gedmo\Mapping\Annotation\TreeRight(array()); + $tree = new \Gedmo\Mapping\Annotation\TreeRoot(array()); + $tree = new \Gedmo\Mapping\Annotation\TreeLevel(array()); + $tree = new \Gedmo\Mapping\Annotation\Versioned(array()); + $tree = new \Gedmo\Mapping\Annotation\Loggable(array()); + $tree = new \Gedmo\Loggable\Entity\LogEntry(); + + // Setting Doctrine2 extensions + $timestampableListener = new \Gedmo\Timestampable\TimestampableListener(); + // $app['db.event_manager']->addEventSubscriber($timestampableListener); + $this['dbs.event_manager']['db_read']->addEventSubscriber($timestampableListener); + $this['dbs.event_manager']['db_write']->addEventSubscriber($timestampableListener); + + $sluggableListener = new \Gedmo\Sluggable\SluggableListener(); + // $this['db.event_manager']->addEventSubscriber($sluggableListener); + $this['dbs.event_manager']['db_read']->addEventSubscriber($sluggableListener); + $this['dbs.event_manager']['db_write']->addEventSubscriber($sluggableListener); + + $sortableListener = new \Gedmo\Sortable\SortableListener(); + // $this['db.event_manager']->addEventSubscriber($sortableListener); + $this['dbs.event_manager']['db_read']->addEventSubscriber($sortableListener); + $this['dbs.event_manager']['db_write']->addEventSubscriber($sortableListener); + + $treeListener = new \Gedmo\Tree\TreeListener(); + //$treeListener->setAnnotationReader($cachedAnnotationReader); + // $this['db.event_manager']->addEventSubscriber($treeListener); + $this['dbs.event_manager']['db_read']->addEventSubscriber($treeListener); + $this['dbs.event_manager']['db_write']->addEventSubscriber($treeListener); + + $loggableListener = new \Gedmo\Loggable\LoggableListener(); + if (PHP_SAPI != 'cli') { + //$userInfo = api_get_user_info(); + if (isset($userInfo) && !empty($userInfo['username'])) { + //$loggableListener->setUsername($userInfo['username']); + } + } + $this['dbs.event_manager']['db_read']->addEventSubscriber($loggableListener); + $this['dbs.event_manager']['db_write']->addEventSubscriber($loggableListener); + } + + } } diff --git a/src/ChamiloLMS/Resources/config/prod.php b/src/ChamiloLMS/Resources/config/prod.php index 6d6416d5da..bf6e0c3f24 100644 --- a/src/ChamiloLMS/Resources/config/prod.php +++ b/src/ChamiloLMS/Resources/config/prod.php @@ -13,7 +13,7 @@ $app['temp.paths'] = new stdClass(); $app['temp.paths']->folders[] = $app['path.data']; // Monolog. -$app['temp.paths']->folders[] = $app['path.log']; +$app['temp.paths']->folders[] = $app['path.logs']; // Twig cache. $app['temp.paths']->folders[] = $app['twig.cache.path'] = $app['temp.path'].'twig'; @@ -101,13 +101,13 @@ if ($app['assetic.enabled']) { $app['temp.paths']->folders[] = $app['assetic.path_to_web'].'/js'; $app['temp.paths']->copyFolders = array( - $app['root_sys'].'main/css/'.$app['app.theme'] => $app['assetic.path_to_web'].'/css/'.$app['app.theme'] + $app['path.base'].'main/css/'.$app['app.theme'] => $app['assetic.path_to_web'].'/css/'.$app['app.theme'] ); //} } // Monolog log file -$app['chamilo.log'] = $app['path.log'].'chamilo.log'; +$app['chamilo.log'] = $app['path.logs'].'chamilo.log'; // If the chamilo.lig is not writable try to delete it if (is_file($app['chamilo.log']) && !is_writable($app['chamilo.log'])) { diff --git a/src/ChamiloLMS/app.php b/src/ChamiloLMS/app.php index 6c08fb4448..eda09f8c30 100644 --- a/src/ChamiloLMS/app.php +++ b/src/ChamiloLMS/app.php @@ -202,7 +202,7 @@ $app->error( // Checking if we have a valid language. If not we set it to the platform language. $cidReset = null; -require_once $basePath . 'src/ChamiloLMS/filters.php'; +require_once $app['path.app'].'filters.php'; // The global variable $charset has been defined in a language file too (trad4all.inc.php), this is legacy situation. // So, we have to reassign this variable again in order to keep its value right. @@ -216,57 +216,9 @@ $text_dir = api_get_text_direction(); $app['is_admin'] = false; /** Including routes */ -require_once 'routes.php'; +require_once $app['path.app'].'routes.php'; // Setting doctrine2 extensions - -if (isset($app->getConfiguration()->main_database) && isset($app['db.event_manager'])) { - - // @todo improvement do not create every time this objects - $sortableGroup = new Gedmo\Mapping\Annotation\SortableGroup(array()); - $sortablePosition = new Gedmo\Mapping\Annotation\SortablePosition(array()); - $tree = new Gedmo\Mapping\Annotation\Tree(array()); - $tree = new Gedmo\Mapping\Annotation\TreeParent(array()); - $tree = new Gedmo\Mapping\Annotation\TreeLeft(array()); - $tree = new Gedmo\Mapping\Annotation\TreeRight(array()); - $tree = new Gedmo\Mapping\Annotation\TreeRoot(array()); - $tree = new Gedmo\Mapping\Annotation\TreeLevel(array()); - $tree = new Gedmo\Mapping\Annotation\Versioned(array()); - $tree = new Gedmo\Mapping\Annotation\Loggable(array()); - $tree = new Gedmo\Loggable\Entity\LogEntry(); - - // Setting Doctrine2 extensions - $timestampableListener = new \Gedmo\Timestampable\TimestampableListener(); - // $app['db.event_manager']->addEventSubscriber($timestampableListener); - $app['dbs.event_manager']['db_read']->addEventSubscriber($timestampableListener); - $app['dbs.event_manager']['db_write']->addEventSubscriber($timestampableListener); - - $sluggableListener = new \Gedmo\Sluggable\SluggableListener(); - // $app['db.event_manager']->addEventSubscriber($sluggableListener); - $app['dbs.event_manager']['db_read']->addEventSubscriber($sluggableListener); - $app['dbs.event_manager']['db_write']->addEventSubscriber($sluggableListener); - - $sortableListener = new Gedmo\Sortable\SortableListener(); - // $app['db.event_manager']->addEventSubscriber($sortableListener); - $app['dbs.event_manager']['db_read']->addEventSubscriber($sortableListener); - $app['dbs.event_manager']['db_write']->addEventSubscriber($sortableListener); - - $treeListener = new \Gedmo\Tree\TreeListener(); - //$treeListener->setAnnotationReader($cachedAnnotationReader); - // $app['db.event_manager']->addEventSubscriber($treeListener); - $app['dbs.event_manager']['db_read']->addEventSubscriber($treeListener); - $app['dbs.event_manager']['db_write']->addEventSubscriber($treeListener); - - $loggableListener = new \Gedmo\Loggable\LoggableListener(); - if (PHP_SAPI != 'cli') { - //$userInfo = api_get_user_info(); - - if (isset($userInfo) && !empty($userInfo['username'])) { - //$loggableListener->setUsername($userInfo['username']); - } - } - $app['dbs.event_manager']['db_read']->addEventSubscriber($loggableListener); - $app['dbs.event_manager']['db_write']->addEventSubscriber($loggableListener); -} +$app->setupDoctrineExtensions(); return $app; diff --git a/src/ChamiloLMS/paths.php b/src/ChamiloLMS/paths.php new file mode 100644 index 0000000000..6f49b8fa4e --- /dev/null +++ b/src/ChamiloLMS/paths.php @@ -0,0 +1,21 @@ + __DIR__.'/../../', + /* Application path */ + 'app' => __DIR__.'/../../src/ChamiloLMS', + /* Config */ + 'config' => __DIR__.'/../../config', + + // Can be overwritten in configuration.php + /* data */ + 'data' => __DIR__.'/../../data', + /* temp */ + 'temp' => __DIR__.'/../../data/temp', + /* courses */ + 'courses' => __DIR__.'/../../data/courses', + /* Log */ + 'logs' => __DIR__.'/../../logs', +); diff --git a/src/ChamiloLMS/services.php b/src/ChamiloLMS/services.php index a718c2fc1e..117207cf59 100644 --- a/src/ChamiloLMS/services.php +++ b/src/ChamiloLMS/services.php @@ -660,7 +660,7 @@ class ChamiloServiceProvider implements ServiceProviderInterface 'sys_data_path' => $app['path.data'], 'sys_config_path' => $app['path.config'], 'path.temp' => $app['path.temp'], - 'sys_log_path' => $app['path.log'] + 'sys_log_path' => $app['path.logs'] ); });