Author: Jonathan.Wage
Date: 2010-01-17 09:53:36 +0100 (Sun, 17 Jan 2010)
New Revision: 26754
Added:
plugins/sfSympalPlugin/trunk/lib/task/sfSympalDisableForAppTask.class.php
plugins/sfSympalPlugin/trunk/lib/task/sfSympalEnableForAppTask.class.php
Removed:
plugins/sfSympalPlugin/trunk/lib/task/sfSympalPrepareApplicationTask.class.php
Modified:
plugins/sfSympalPlugin/trunk/config/app.yml
plugins/sfSympalPlugin/trunk/lib/core/sfSympalActions.class.php
plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalSite.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_sites/lib/Basesympal_sitesActions.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/templates/admin.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/lib/sfSympalInstall.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/lib/task/sfSympalInstallTask.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/modules/sympal_install/lib/Basesympal_installActions.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
plugins/sfSympalPlugin/trunk/lib/task/sfSympalBaseTask.class.php
plugins/sfSympalPlugin/trunk/lib/task/sfSympalCreateSiteTask.class.php
plugins/sfSympalPlugin/trunk/lib/task/sfSympalDeleteSiteTask.class.php
plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
plugins/sfSympalPlugin/trunk/modules/sympal_default/templates/ask_confirmationSuccess.php
plugins/sfSympalPlugin/trunk/modules/sympal_default/templates/new_siteSuccess.php
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/config/sympalConfiguration.class.php
plugins/sfSympalPlugin/trunk/test/fixtures/project/config/databases.yml
plugins/sfSympalPlugin/trunk/test/fixtures/project/data/fresh_test_db.sqlite
plugins/sfSympalPlugin/trunk/test/unit/ConfigurationTest.php
Log:
[1.4][sfSympalPlugin][1.0] Improving workflow for working with multiple sites
from the command line and in the web in dev mode
Modified: plugins/sfSympalPlugin/trunk/config/app.yml
===================================================================
--- plugins/sfSympalPlugin/trunk/config/app.yml 2010-01-17 07:28:27 UTC (rev
26753)
+++ plugins/sfSympalPlugin/trunk/config/app.yml 2010-01-17 08:53:36 UTC (rev
26754)
@@ -223,6 +223,7 @@
# Configure internationalization
i18n: false
+
# Configure what models and fields get internationalized by Sympal
internationalized_models:
sfSympalContent: [i18n_slug, page_title, meta_keywords, meta_description]
Modified: plugins/sfSympalPlugin/trunk/lib/core/sfSympalActions.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/core/sfSympalActions.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++ plugins/sfSympalPlugin/trunk/lib/core/sfSympalActions.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -197,4 +197,9 @@
{
$this->redirect($this->getRequest()->getReferer());
}
+
+ public function refresh()
+ {
+ $this->redirect($this->getRequest()->getUri());
+ }
}
\ No newline at end of file
Modified: plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++ plugins/sfSympalPlugin/trunk/lib/core/sfSympalConfiguration.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -97,7 +97,7 @@
$this->_enableModules();
- $this->_redirectIfNotInstalled();
+ $this->_checkSympalInstall();
$this->initializeTheme();
@@ -318,11 +318,21 @@
}
}
- private function _redirectIfNotInstalled()
+ private function _checkSympalInstall()
{
$sfContext = sfContext::getInstance();
$request = $sfContext->getRequest();
+ // Prepare the symfony application is it has not been prepared yet
+ if (!$sfContext->getUser() instanceof sfSympalUser)
+ {
+ chdir(sfConfig::get('sf_root_dir'));
+ $task = new sfSympalEnableForAppTask($this->_dispatcher, new
sfFormatter());
+ $task->run(array($this->_projectConfiguration->getApplication()),
array());
+
+ $sfContext->getController()->redirect('@homepage');
+ }
+
// Redirect to install module if...
// not in test environment
// sympal has not been installed
@@ -331,6 +341,14 @@
{
$sfContext->getController()->redirect('@sympal_install');
}
+
+ // Redirect to homepage if no site record exists so we can prompt the user
to create
+ // a site record for this application
+ // This check is only ran in dev mode
+ if (sfConfig::get('sf_environment') == 'dev' &&
!$this->_sympalContext->getSite() && $sfContext->getRequest()->getPathInfo() !=
'/')
+ {
+ $sfContext->getController()->redirect('@homepage');
+ }
}
private function _initializeSymfonyConfig()
Modified:
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalSite.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalSite.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalSite.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -11,7 +11,7 @@
$this->deleteApplication();
}
- public function deleteApplication(Doctrine_Connection $conn = null)
+ public function deleteApplication()
{
sfToolkit::clearDirectory(sfConfig::get('sf_apps_dir').'/'.$this->slug);
rmdir(sfConfig::get('sf_apps_dir').'/'.$this->slug);
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_sites/lib/Basesympal_sitesActions.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_sites/lib/Basesympal_sitesActions.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/modules/sympal_sites/lib/Basesympal_sitesActions.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -22,7 +22,7 @@
chdir(sfConfig::get('sf_root_dir'));
$task = new sfGenerateAppTask($dispatcher, $formatter);
$task->run(array($name));
- $task = new sfSympalPrepareApplicationTask($dispatcher, $formatter);
+ $task = new sfSympalEnableForAppTask($dispatcher, $formatter);
$task->run(array($name));
$task = new sfSympalCreateSiteTask($dispatcher, $formatter);
$task->run(array($name));
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/templates/admin.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/templates/admin.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalAdminPlugin/templates/admin.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -20,7 +20,7 @@
<!-- content -->
<div id="content">
- <?php if (!$sf_request->getParameter('popup') &&
$sf_user->isAuthenticated()): ?>
+ <?php if (!$sf_request->getParameter('popup') && $sf_user->isAuthenticated()
&& $sf_sympal_context->getSite()): ?>
<div id="header">
<h1><?php echo $sf_sympal_context->getSite()->getTitle() ?> <?php echo
sfSympalConfig::getCurrentVersion() ?> Admin</h1>
</div>
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/lib/sfSympalInstall.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/lib/sfSympalInstall.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/lib/sfSympalInstall.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -7,6 +7,7 @@
$_dispatcher,
$_formatter,
$_application = 'sympal',
+ $_forceReinstall = false,
$_params = array(
'db_dsn' => null,
'db_username' => null,
@@ -34,6 +35,11 @@
$this->_application = $application;
}
+ public function setConfiguration(ProjectConfiguration $configuration)
+ {
+ $this->_configuration = $configuration;
+ }
+
public function getParam($key)
{
return $this->_params[$key];
@@ -54,6 +60,11 @@
$this->_params = $params;
}
+ public function setForceReinstall($bool)
+ {
+ $this->_forceReinstall = $bool;
+ }
+
public function logSection($section, $message, $size = null, $style = 'INFO')
{
$this->_configuration->getEventDispatcher()->notify(new sfEvent($this,
'command.log', array($this->_formatter->formatSection($section, $message,
$size, $style))));
@@ -68,38 +79,60 @@
// Prepare the installation parameters
$this->_prepareParams();
- // Setup/create the Sympal database
- $this->_setupDatabase();
+ // Build all classes
+ $this->_buildAllClasses();
- // Install Sympal to the database
- $this->_installSympal();
+ $dbExists = $this->checkSympalDatabaseExists();
- // Run installation procss for any addon plugins
- $this->_installAddonPlugins();
+ // If database does not exist or we are forcing a reinstall then lets do a
full install
+ if (!$dbExists || $this->_forceReinstall)
+ {
+ // Setup/create the Sympal database
+ $this->_setupDatabase();
- // Execute post install execute
- $this->_executePostInstallSql();
+ // Install Sympal to the database
+ $this->_installSympal();
- // Execute post install hooks
- $this->_executePostInstallHooks();
+ // Run installation procss for any addon plugins
+ $this->_installAddonPlugins();
- // Publish plugin assets
- $this->_publishAssets();
+ // Execute post install execute
+ $this->_executePostInstallSql();
- // Clear the cache
- $this->_clearCache();
+ // Execute post install hooks
+ $this->_executePostInstallHooks();
+ // If db exists and site does not exist then lets create the site
+ } else if ($dbExists && !$this->checkSympalSiteExists()) {
+ $this->_createSite();
+ // Delete site and recreate it
+ } else {
+ Doctrine_Manager::connection()->execute('delete from sf_sympal_site
where slug = ?', array($this->_application));
+ $this->_createSite();
+ }
- // Prime the cache
- $this->_primeCache();
+ if (!$dbExists || $this->_forceReinstall)
+ {
+ // Publish plugin assets
+ $this->_publishAssets();
+ // Clear the cache
+ $this->_clearCache();
+
+ // Prime the cache
+ $this->_primeCache();
+ }
+
sfSympalConfig::writeSetting('installed', true);
sfSympalConfig::set('installing', false);
sfSympalConfig::writeSetting('current_version',
sfSympalPluginConfiguration::VERSION);
$this->_dispatcher->notify(new sfEvent($this, 'sympal.post_install',
array('configuration' => $this->_configuration, 'dispatcher' =>
$this->_dispatcher, 'formatter' => $this->_formatter)));
- // Run fix permissions to ensure a 100% ready to go environment
- $this->_fixPerms();
+ if (!$dbExists || $this->_forceReinstall)
+ {
+ // Run fix permissions to ensure a 100% ready to go environment
+ $this->_fixPerms();
+ }
}
protected function _prepareParams()
@@ -113,6 +146,48 @@
}
}
+ public function checkSympalSiteExists()
+ {
+ try {
+ $conn = Doctrine_Manager::connection();
+ $result = $conn->fetchColumn('select slug from sf_sympal_site where slug
= ?', array($this->_application));
+ $return = isset($result[0]) && $result[0] == $this->_application;
+ } catch (Exception $e) {
+ $return = false;
+ }
+ $conn->close();
+ return $return;
+ }
+
+ public function checkSympalDatabaseExists()
+ {
+ try {
+ $conn = Doctrine_Manager::connection();
+ $conn->fetchColumn('select slug from sf_sympal_site where slug = ?',
array($this->_application));
+ $return = true;
+ } catch (Exception $e) {
+ $return = false;
+ }
+ $conn->close();
+ return $return;
+ }
+
+ private function _createSite()
+ {
+ chdir(sfConfig::get('sf_root_dir'));
+ $task = new sfSympalCreateSiteTask($this->_dispatcher, $this->_formatter);
+ $task->run(array($this->_application), array('no-confirmation' => true));
+ }
+
+ protected function _buildAllClasses()
+ {
+ $this->logSection('sympal', '...building all classes', null, 'COMMENT');
+
+ chdir(sfConfig::get('sf_root_dir'));
+ $task = new sfDoctrineBuildTask($this->_dispatcher, $this->_formatter);
+ $task->run(array(), array('all-classes',
'--application='.sfConfig::get('sf_app')));
+ }
+
protected function _setupDatabase()
{
if (isset($this->_params['db_dsn']) &&
isset($this->_params['db_username']))
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/lib/task/sfSympalInstallTask.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/lib/task/sfSympalInstallTask.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/lib/task/sfSympalInstallTask.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -5,20 +5,21 @@
protected function configure()
{
$this->addArguments(array(
- new sfCommandArgument('email-address', sfCommandArgument::OPTIONAL, 'The
e-mail address of the first user to create.', '[email protected]'),
- new sfCommandArgument('username', sfCommandArgument::OPTIONAL, 'The
username of the first user to create.', 'admin'),
- new sfCommandArgument('password', sfCommandArgument::OPTIONAL, 'The
password of the first user to create.', 'admin'),
+ new sfCommandArgument('application', sfCommandArgument::OPTIONAL, 'The
application to install Sympal in.', sfSympalToolkit::getDefaultApplication()),
));
$this->addOptions(array(
+ new sfCommandOption('email-address', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The e-mail address of the first user to
create', '[email protected]'),
+ new sfCommandOption('username', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The username of the first user to
create.', 'admin'),
+ new sfCommandOption('password', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The password of the first user to
create.', 'admin'),
new sfCommandOption('first-name', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The first name of the first user to
create.'),
new sfCommandOption('last-name', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The last name of the first user to
create.'),
new sfCommandOption('db-dsn', null, sfCommandOption::PARAMETER_OPTIONAL,
'The database DSN to install with.'),
new sfCommandOption('db-username', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The database username.'),
new sfCommandOption('db-password', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The database password.'),
- new sfCommandOption('application', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The title of the Sympal site to install',
sfSympalToolkit::getDefaultApplication()),
+ new sfCommandOption('no-confirmation', null,
sfCommandOption::PARAMETER_NONE, 'Do not ask for confirmation'),
+ new sfCommandOption('force-reinstall', null,
sfCommandOption::PARAMETER_NONE, 'Force re-installation'),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
'The environment', 'dev'),
- new sfCommandOption('no-confirmation', null,
sfCommandOption::PARAMETER_NONE, 'Do not ask for confirmation'),
));
$this->aliases = array();
@@ -32,10 +33,13 @@
[./symfony sympal:install|INFO]
By default the task will find the first application in the apps folder and
install
-Sympal for that application. You can specify the application with the
--application
-option:
+Sympal for that application. You can specify the application with the first
argument.
- [./symfony sympal:install --application=my_app|INFO]
+ [./symfony sympal:install my_app|INFO]
+
+To force a full reinstall of sympal use the force-reinstall option:
+
+ [./symfony sympal:install --force-reinstall|INFO]
EOF;
}
@@ -44,20 +48,46 @@
*/
protected function execute($arguments = array(), $options = array())
{
- if (!$options['no-confirmation'] && !$this->askConfirmation(array('This
command will remove all data in your configured databases and initialize the
sympal database.', 'Are you sure you want to proceed? (y/N)'),
'QUESTION_LARGE', false))
+ $databaseManager = new sfDatabaseManager($this->configuration);
+
+ $install = new sfSympalInstall($this->configuration, $this->dispatcher,
$this->formatter);
+ $install->setApplication($arguments['application']);
+
+ $msg = array();
+ if (isset($options['force-reinstall']) && $options['force-reinstall']) {
+ $msg[] = 'This command will remove all data in your configured databases
and initialize the Sympal database.';
+ $type = 'ERROR_LARGE';
+ } else if ($install->checkSympalSiteExists()) {
+ $msg[] = sprintf('Sympal has already been installed for the application
named "%s".', $arguments['application']);
+ $msg[] = 'Do you wish to delete the site and re-create it?';
+ $msg[] = '';
+ $msg[] = 'Use the --force-reinstall option to reinstall Sympal
completely.';
+ $msg[] = '';
+ $type = 'ERROR_LARGE';
+ } else if ($install->checkSympalDatabaseExists() &&
!$install->checkSympalSiteExists()) {
+ $msg[] = sprintf('Sympal has already been installed but the application
named "%s" has not had a site created for it yet.', $arguments['application']);
+ $msg[] = 'Do you want to create a site record for this application?';
+ $msg[] = '';
+ $msg[] = 'Use the --force-reinstall option to reinstall Sympal
completely.';
+ $msg[] = '';
+ $type = 'QUESTION_LARGE';
+ } else {
+ $msg[] = sprintf('This command will initialize the sympal Database for
the application named "%s".', $arguments['application']);
+ $type = 'QUESTION_LARGE';
+ }
+
+ $msg[] = 'Are you sure you want to proceed? (y/N)';
+
+ if (!$options['no-confirmation'] && !$this->askConfirmation($msg, $type,
false))
{
$this->logSection('sympal', 'Install task aborted');
return 1;
}
- $databaseManager = new sfDatabaseManager($this->configuration);
-
- $install = new sfSympalInstall($this->configuration, $this->dispatcher,
$this->formatter);
- $install->setApplication($options['application']);
- $install->setParam('email_address', $arguments['email-address']);
- $install->setParam('username', $arguments['username']);
- $install->setParam('password', $arguments['password']);
+ $install->setParam('email_address', $options['email-address']);
+ $install->setParam('username', $options['username']);
+ $install->setParam('password', $options['password']);
if (isset($options['first-name']))
{
$install->setParam('first_name', $options['first-name']);
@@ -78,13 +108,17 @@
{
$install->setParam('db_password', $options['db-password']);
}
+ if (isset($options['force-reinstall']) && $options['force-reinstall'])
+ {
+ $install->setForceReinstall(true);
+ }
$install->install();
$this->log(null);
- $this->logSection('sympal', sprintf('Sympal was installed
successfully...', $options['application']), null, 'COMMENT');
+ $this->logSection('sympal', sprintf('Sympal was installed
successfully...', $arguments['application']), null, 'COMMENT');
- $url =
'http://localhost/'.$options['application'].'_dev.php/security/signin';
+ $url =
'http://localhost/'.$arguments['application'].'_dev.php/security/signin';
$this->logSection('sympal', sprintf('Open your browser to "%s"', $url),
null, 'COMMENT');
$this->logSection('sympal', sprintf('You can signin with the username "%s"
and password "%s"', $install->getParam('username'),
$install->getParam('password')), null, 'COMMENT');
}
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/modules/sympal_install/lib/Basesympal_installActions.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/modules/sympal_install/lib/Basesympal_installActions.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalInstallPlugin/modules/sympal_install/lib/Basesympal_installActions.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -77,6 +77,7 @@
chdir(sfConfig::get('sf_root_dir'));
$install = new
sfSympalInstall($this->getContext()->getConfiguration(),
$this->getContext()->getEventDispatcher(), $formatter);
$install->setParams($params);
+ $install->setForceReinstall(true);
$install->install();
} catch (Exception $e) {
$this->getUser()->setFlash('error', $e->getMessage());
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalRenderingPlugin/lib/sfSympalContentActionLoader.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -27,6 +27,7 @@
$this->_content = $this->_actions->getRoute()->getObject();
if ($this->_content)
{
+ $this->_sympalContext->setSite($this->_content->getSite());
$this->_menuItem = $this->_content->getMenuItem();
}
}
@@ -162,6 +163,13 @@
return $title;
}
+ private function _createSite()
+ {
+ chdir(sfConfig::get('sf_root_dir'));
+ $task = new
sfSympalCreateSiteTask($this->_actions->getContext()->getEventDispatcher(), new
sfFormatter());
+ $task->run(array($this->_sympalContext->getSiteSlug()),
array('no-confirmation' => true));
+ }
+
private function _handleForward404($record)
{
if (!$record)
@@ -171,13 +179,14 @@
// No site record exception
if (!$site)
{
- $message = sprintf(
- 'The Symfony application "%s" does not have a site record in the
database. You must create a site with the sympal:create-site %s task and then
install with the sympal:install %s task in order to get started.',
- sfConfig::get('sf_app'),
- sfConfig::get('sf_app'),
- sfConfig::get('sf_app')
+ // Site doesn't exist for this application make sure the user wants to
create a site for this application
+ $this->_actions->askConfirmation(
+ sprintf('No site found for the application named "%s"',
$this->_sympalContext->getSiteSlug()),
+ sprintf('Do you want to create a site for the application named
"%s"? Clicking yes will create a site record in the database and allow you to
begin building out the content for your site!',
$this->_sympalContext->getSiteSlug())
);
- throw new sfException($message);
+
+ $this->_createSite();
+ $this->_actions->refresh();
// Check for no content and redirect to default new site page
} else {
$q = Doctrine_Query::create()
Modified: plugins/sfSympalPlugin/trunk/lib/task/sfSympalBaseTask.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/task/sfSympalBaseTask.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++ plugins/sfSympalPlugin/trunk/lib/task/sfSympalBaseTask.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -11,4 +11,10 @@
{
return new sfDatabaseManager($this->configuration);
}
+
+ public function clearCache(array $options = array())
+ {
+ $task = new sfCacheClearTask($this->dispatcher, $this->formatter);
+ $task->run(array(), $options);
+ }
}
\ No newline at end of file
Modified: plugins/sfSympalPlugin/trunk/lib/task/sfSympalCreateSiteTask.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/task/sfSympalCreateSiteTask.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++ plugins/sfSympalPlugin/trunk/lib/task/sfSympalCreateSiteTask.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -5,11 +5,10 @@
protected function configure()
{
$this->addArguments(array(
- new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The
site/application title'),
+ new sfCommandArgument('site', sfCommandArgument::REQUIRED, 'The site'),
));
$this->addOptions(array(
- new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
'The environment', 'dev'),
new sfCommandOption('layout', null, sfCommandOption::PARAMETER_OPTIONAL,
'The site/application layout', null),
new sfCommandOption('interactive', null,
sfCommandOption::PARAMETER_NONE, 'Interactive installation option'),
new sfCommandOption('load-dummy-data', null,
sfCommandOption::PARAMETER_NONE, 'Load dummy data for the newly created site.'),
@@ -29,20 +28,51 @@
EOF;
}
+ protected function execute($arguments = array(), $options = array())
+ {
+ if (!$options['no-confirmation'] &&
!$this->askConfirmation(array(sprintf('You are about to create a new site named
"%s"', $arguments['site']), 'Are you sure you want to proceed? (y/N)'),
'QUESTION_LARGE', false))
+ {
+ $this->logSection('sympal', 'Install task aborted');
+
+ return 1;
+ }
+
+ if (isset($options['interactive']) && $options['interactive'])
+ {
+ sfSympalConfig::set('sympal_install_admin_email_address',
$this->askAndValidate('Enter E-Mail Address:', new sfValidatorString()));
+ sfSympalConfig::set('sympal_install_admin_first_name',
$this->askAndValidate('Enter First Name:', new sfValidatorString()));
+ sfSympalConfig::set('sympal_install_admin_last_name',
$this->askAndValidate('Enter Last Name:', new sfValidatorString()));
+ sfSympalConfig::set('sympal_install_admin_username',
$this->askAndValidate('Enter Username:', new sfValidatorString()));
+ sfSympalConfig::set('sympal_install_admin_password',
$this->askAndValidate('Enter Password:', new sfValidatorString()));
+ }
+
+ $this->_generateApplication($arguments['site']);
+ $this->_prepareApplication($arguments['site']);
+
+ $this->configuration = $this->createConfiguration($arguments['site'],
'dev');
+ $context = sfContext::createInstance($this->configuration);
+
+ $databaseManager = new sfDatabaseManager($this->configuration);
+ $site = $this->_getOrCreateSite($arguments, $options);
+ }
+
protected function _getOrCreateSite($arguments, $options)
{
- $site =
Doctrine_Core::getTable('sfSympalSite')->findOneBySlug($arguments['application']);
+ $site = Doctrine_Core::getTable('sfSympalSite')
+ ->createQuery('s')
+ ->where('s.slug = ?', $arguments['site'])
+ ->fetchOne();
if (!$site)
{
$this->logSection('sympal', 'Creating new site record in database...');
$site = new sfSympalSite();
- $site->title = $arguments['application'];
- $site->slug = $arguments['application'];
+ $site->title = sfInflector::humanize($arguments['site']);
+ $site->slug = $arguments['site'];
}
if (!$site->description)
{
- $site->description = 'Description for '.$arguments['application'].'
site.';
+ $site->description = 'Description for '.$arguments['site'].' site.';
}
if ($options['layout'])
@@ -55,43 +85,17 @@
return $site;
}
- protected function _prepareApplication(sfSympalSite $site)
+ protected function _generateApplication($application)
{
- $task = new sfSympalPrepareApplicationTask($this->dispatcher,
$this->formatter);
- $task->run(array($site->slug), array());
+ try {
+ $task = new sfGenerateAppTask($this->dispatcher, $this->formatter);
+ $task->run(array($application), array());
+ } catch (Exception $e) {}
}
- protected function _installSiteData()
+ protected function _prepareApplication($application)
{
+ $task = new sfSympalEnableForAppTask($this->dispatcher, $this->formatter);
+ $task->run(array($application), array());
}
-
- protected function execute($arguments = array(), $options = array())
- {
- if (!$options['no-confirmation'] &&
!$this->askConfirmation(array(sprintf('You are about to create a new site named
%s', $arguments['application']), 'Are you sure you want to proceed? (y/N)'),
'QUESTION_LARGE', false))
- {
- $this->logSection('sympal', 'Install task aborted');
-
- return 1;
- }
-
- $path = sfConfig::get('sf_apps_dir').'/'.$arguments['application'];
- if (!file_exists($path))
- {
- throw new sfException(sprintf('Could not find a Symfony application
named "%s". You must generate an application with the generate:app task.',
$options['application']));
- }
-
- if (isset($options['interactive']) && $options['interactive'])
- {
- sfSympalConfig::set('sympal_install_admin_email_address',
$this->askAndValidate('Enter E-Mail Address:', new sfValidatorString()));
- sfSympalConfig::set('sympal_install_admin_first_name',
$this->askAndValidate('Enter First Name:', new sfValidatorString()));
- sfSympalConfig::set('sympal_install_admin_last_name',
$this->askAndValidate('Enter Last Name:', new sfValidatorString()));
- sfSympalConfig::set('sympal_install_admin_username',
$this->askAndValidate('Enter Username:', new sfValidatorString()));
- sfSympalConfig::set('sympal_install_admin_password',
$this->askAndValidate('Enter Password:', new sfValidatorString()));
- }
-
- $databaseManager = new sfDatabaseManager($this->configuration);
- $site = $this->_getOrCreateSite($arguments, $options);
- $this->_prepareApplication($site);
- $this->_installSiteData($site);
- }
}
\ No newline at end of file
Modified: plugins/sfSympalPlugin/trunk/lib/task/sfSympalDeleteSiteTask.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/task/sfSympalDeleteSiteTask.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++ plugins/sfSympalPlugin/trunk/lib/task/sfSympalDeleteSiteTask.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -9,7 +9,6 @@
));
$this->addOptions(array(
- new sfCommandOption('application', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The application name',
sfSympalToolkit::getDefaultApplication()),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
'The environment', 'dev'),
new sfCommandOption('and-app', null, sfCommandOption::PARAMETER_NONE,
'Delete Symfony application directory as well.'),
new sfCommandOption('no-confirmation', null,
sfCommandOption::PARAMETER_NONE, 'Do not ask for confirmation'),
@@ -37,7 +36,7 @@
*/
protected function execute($arguments = array(), $options = array())
{
- if (!$options['no-confirmation'] &&
!$this->askConfirmation(array(sprintf('You are about to delete the site named
%s', $arguments['application']), 'Are you sure you want to proceed? (y/N)'),
'QUESTION_LARGE', false))
+ if (!$options['no-confirmation'] &&
!$this->askConfirmation(array(sprintf('You are about to delete the site named
"%s"', $arguments['application']), 'Are you sure you want to proceed? (y/N)'),
'QUESTION_LARGE', false))
{
$this->logSection('sympal', 'Delete site task aborted');
@@ -55,7 +54,7 @@
if (isset($options['and-app']) && $options['and-app'])
{
- $this->logSection('sympal', sprintf('Deleting Symfony application named
"%s"', $arguments['application']));
+ $this->logSection('sympal', sprintf('Deleting Symfony application named
"%s"...', $arguments['application']));
sfToolkit::clearDirectory(sfConfig::get('sf_apps_dir').'/'.$arguments['application']);
rmdir(sfConfig::get('sf_apps_dir').'/'.$arguments['application']);
Added: plugins/sfSympalPlugin/trunk/lib/task/sfSympalDisableForAppTask.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/task/sfSympalDisableForAppTask.class.php
(rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/task/sfSympalDisableForAppTask.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -0,0 +1,73 @@
+<?php
+
+class sfSympalDisableForAppTask extends sfSympalBaseTask
+{
+ protected function configure()
+ {
+ $this->addArguments(array(
+ new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The
application to delete'),
+ ));
+
+ $this->addOptions(array(
+ new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
'The environment', 'dev')
+ ));
+
+ $this->aliases = array();
+ $this->namespace = 'sympal';
+ $this->name = 'disable-for-app';
+ $this->briefDescription = 'Disable Sympal for the specified application';
+
+ $this->detailedDescription = <<<EOF
+The [symfony sympal:disable-for-app|INFO] disables Sympal from being loaded
for the specified app.
+
+ [./symfony sympal:disable-for-app my_app|INFO]
+EOF;
+ }
+
+ /**
+ * @see sfTask
+ */
+ protected function execute($arguments = array(), $options = array())
+ {
+ $this->logSection('sympal', sprintf('Disabling Sympal for Symfony
application named "%s"...', $arguments['application']));
+
+ if ($this->isSympalEnabled())
+ {
+ $path =
sfConfig::get('sf_app_dir').'/config/'.$arguments['application'].'Configuration.class.php';
+ $find = sprintf('class %sConfiguration extends sfApplicationConfiguration
+{', $arguments['application']);
+ $replace = sprintf('class %sConfiguration extends
sfApplicationConfiguration
+{
+ const disableSympal = true;
+', $arguments['application']);
+ $code = file_get_contents($path);
+ $code = str_replace($find, $replace, $code);
+ file_put_contents($path, $code);
+
+ $this->logSection('sympal', '...disabling Sympal in application
configuration class', null, 'COMMENT');
+ }
+
+ $this->logSection('sympal', '...reverting class myUser extends', null,
'COMMENT');
+
+ $path = sfConfig::get('sf_app_dir').'/lib/myUser.class.php';
+ $code = file_get_contents($path);
+ $find = 'class myUser extends sfSympalUser';
+ $replace = 'class myUser extends sfBasicSecurityUser';
+ file_put_contents($path, str_replace($find, $replace, $code));
+
+ $this->clearCache();
+ }
+
+ public function isSympalEnabled()
+ {
+ if ($application = sfConfig::get('sf_app'))
+ {
+ $reflection = new ReflectionClass($application.'Configuration');
+ if ($reflection->getConstant('disableSympal'))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
Added: plugins/sfSympalPlugin/trunk/lib/task/sfSympalEnableForAppTask.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/task/sfSympalEnableForAppTask.class.php
(rev 0)
+++ plugins/sfSympalPlugin/trunk/lib/task/sfSympalEnableForAppTask.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -0,0 +1,51 @@
+<?php
+
+class sfSympalEnableForAppTask extends sfSympalBaseTask
+{
+ protected function configure()
+ {
+ $this->addArguments(array(
+ new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The
Symfony application to prepare as a Sympal site.'),
+ ));
+
+ $this->aliases = array();
+ $this->namespace = 'sympal';
+ $this->name = 'enable-for-app';
+ $this->briefDescription = 'Prepare a Symfony application to be a Sympal
site';
+
+ $this->detailedDescription = <<<EOF
+The [sympal:prepare-application|INFO] task will prepare a Symfony application
to be a Sympal site
+
+ [./sympal:prepare-application sympal|INFO]
+EOF;
+ }
+
+ protected function execute($arguments = array(), $options = array())
+ {
+ $this->logSection('sympal', sprintf('Preparing Symfony application named
"%s" for Sympal...', $arguments['application']));
+
+ $path =
sfConfig::get('sf_app_dir').'/config/'.$arguments['application'].'Configuration.class.php';
+ $find = ' const disableSympal = true;';
+ $replace = '';
+ $code = file_get_contents($path);
+ $code = str_replace($find, $replace, $code);
+ file_put_contents($path, $code);
+
+ $this->logSection('sympal', '...making sure Sympal is not disabled for
this application', null, 'COMMENT');
+
+ $path = sfConfig::get('sf_apps_dir').'/'.$arguments['application'];
+
+ $code = file_get_contents($path.'/lib/myUser.class.php');
+ file_put_contents($path.'/lib/myUser.class.php', str_replace('class myUser
extends sfBasicSecurityUser', 'class myUser extends sfSympalUser', $code));
+ $this->logSection('sympal', '...modifying myUser to extends sfSympalUser',
null, 'COMMENT');
+
+ $path = sfConfig::get('sf_app_dir').'/config/routing.yml';
+ $array = sfYaml::load($path);
+ unset($array['homepage'], $array['default'], $array['default_index']);
+ file_put_contents($path, sfYaml::dump($array));
+
+ $this->logSection('sympal', '...removing default application default
routes', null, 'COMMENT');
+
+ $this->clearCache();
+ }
+}
\ No newline at end of file
Property changes on:
plugins/sfSympalPlugin/trunk/lib/task/sfSympalEnableForAppTask.class.php
___________________________________________________________________
Added: svn:executable
+ *
Deleted:
plugins/sfSympalPlugin/trunk/lib/task/sfSympalPrepareApplicationTask.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/task/sfSympalPrepareApplicationTask.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/lib/task/sfSympalPrepareApplicationTask.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -1,40 +0,0 @@
-<?php
-
-class sfSympalPrepareApplicationTask extends sfSympalBaseTask
-{
- protected function configure()
- {
- $this->addArguments(array(
- new sfCommandArgument('application', sfCommandArgument::REQUIRED, 'The
Symfony application to prepare as a Sympal site.'),
- ));
-
- $this->aliases = array();
- $this->namespace = 'sympal';
- $this->name = 'prepare-application';
- $this->briefDescription = 'Prepare a Symfony application to be a Sympal
site';
-
- $this->detailedDescription = <<<EOF
-The [sympal:prepare-application|INFO] task will prepare a Symfony application
to be a Sympal site
-
- [./sympal:prepare-application sympal|INFO]
-EOF;
- }
-
- protected function execute($arguments = array(), $options = array())
- {
- $path = sfConfig::get('sf_apps_dir').'/'.$arguments['application'];
-
- $this->logSection('sympal', sprintf('Preparing Symfony application "%s"
for Sympal...', $path));
-
- $code = file_get_contents($path.'/lib/myUser.class.php');
- file_put_contents($path.'/lib/myUser.class.php', str_replace('class myUser
extends sfBasicSecurityUser', 'class myUser extends sfSympalUser', $code));
- $this->logSection('sympal', '...modifying myUser to extends sfSympalUser',
null, 'COMMENT');
-
- $path = sfConfig::get('sf_app_dir').'/config/routing.yml';
- $array = sfYaml::load($path);
- unset($array['homepage'], $array['default'], $array['default_index']);
- file_put_contents($path, sfYaml::dump($array));
-
- $this->logSection('sympal', '...removing default application default
routes', null, 'COMMENT');
- }
-}
\ No newline at end of file
Modified: plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++ plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -34,13 +34,15 @@
foreach ($apps as $app)
{
$info = pathinfo($app);
- require_once
sfConfig::get('sf_apps_dir').'/'.$info['filename'].'/config/'.$info['filename'].'Configuration.class.php';
+ $path = $app.'/config/'.$info['filename'].'Configuration.class.php';
+ require_once $path;
$reflection = new ReflectionClass($info['filename'].'Configuration');
if (!$reflection->getConstant('disableSympal'))
{
return $info['filename'];
}
}
+
return 'sympal';
}
Modified:
plugins/sfSympalPlugin/trunk/modules/sympal_default/templates/ask_confirmationSuccess.php
===================================================================
---
plugins/sfSympalPlugin/trunk/modules/sympal_default/templates/ask_confirmationSuccess.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/modules/sympal_default/templates/ask_confirmationSuccess.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -27,6 +27,8 @@
<?php endforeach; ?>
<input type="submit" name="yes" value="Yes" />
- <input type="submit" name="no" value="No" />
+ <?php if ($sf_request->getReferer()): ?>
+ <input type="submit" name="no" value="No" />
+ <?php endif; ?>
</form>
</div>
\ No newline at end of file
Modified:
plugins/sfSympalPlugin/trunk/modules/sympal_default/templates/new_siteSuccess.php
===================================================================
---
plugins/sfSympalPlugin/trunk/modules/sympal_default/templates/new_siteSuccess.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/modules/sympal_default/templates/new_siteSuccess.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -3,8 +3,12 @@
<p>
<?php echo __('You have successfully created a new Site but no content could
be found.') ?>
<?php if ($sf_user->isAuthenticated()): ?>
- <?php echo __('Go to your %1% to get started working with %2%.', array(
- '%1%' => link_to('Dashboard', '@sympal_dashboard'), '%2%' =>
__('Sympal'))
- ) ?>
+ <?php echo __('Go to your %1% to begin building out the content for your
site!', array(
+ '%1%' => link_to('Dashboard', '@sympal_dashboard'))
+ ) ?>
+ <?php else: ?>
+ <?php echo __('%1% to begin building out the content for your site!',
array(
+ '%1%' => link_to('Signin', '@sympal_signin')
+ )) ?>
<?php endif; ?>
</p>
\ No newline at end of file
Modified:
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/config/sympalConfiguration.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/config/sympalConfiguration.class.php
2010-01-17 07:28:27 UTC (rev 26753)
+++
plugins/sfSympalPlugin/trunk/test/fixtures/project/apps/sympal/config/sympalConfiguration.class.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -2,10 +2,8 @@
class sympalConfiguration extends sfApplicationConfiguration
{
- // Optionally disable sympal for an application.
- // By default sympal is enabled for your applications.
- // const disableSympal = true;
+
public function configure()
{
}
Modified:
plugins/sfSympalPlugin/trunk/test/fixtures/project/config/databases.yml
===================================================================
--- plugins/sfSympalPlugin/trunk/test/fixtures/project/config/databases.yml
2010-01-17 07:28:27 UTC (rev 26753)
+++ plugins/sfSympalPlugin/trunk/test/fixtures/project/config/databases.yml
2010-01-17 08:53:36 UTC (rev 26754)
@@ -2,11 +2,12 @@
doctrine:
class: sfDoctrineDatabase
param:
+ #dsn: 'sqlite:///%SF_DATA_DIR%/test.sqlite'
dsn: 'mysql://root:@localhost/sympal'
- username: root
+ #username: root
test:
doctrine:
param:
dsn: 'sqlite:///%SF_DATA_DIR%/test.sqlite'
- #dsn: mysql://root:@localhost/sympal_test
\ No newline at end of file
+ #dsn: mysql://root:@localhost/sympal_test
Modified:
plugins/sfSympalPlugin/trunk/test/fixtures/project/data/fresh_test_db.sqlite
===================================================================
(Binary files differ)
Modified: plugins/sfSympalPlugin/trunk/test/unit/ConfigurationTest.php
===================================================================
--- plugins/sfSympalPlugin/trunk/test/unit/ConfigurationTest.php
2010-01-17 07:28:27 UTC (rev 26753)
+++ plugins/sfSympalPlugin/trunk/test/unit/ConfigurationTest.php
2010-01-17 08:53:36 UTC (rev 26754)
@@ -9,8 +9,10 @@
$sympalConfiguration = $sympalPluginConfiguration->getSympalConfiguration();
$requiredPlugins = array(
+ 'sfSympalPlugin',
+ 'sfSympalUserPlugin',
+ 'sfFormExtraPlugin',
'sfDoctrineGuardPlugin',
- 'sfFormExtraPlugin',
'sfTaskExtraPlugin',
'sfFeed2Plugin',
'sfWebBrowserPlugin',
@@ -22,14 +24,12 @@
'sfSympalPagesPlugin',
'sfSympalContentListPlugin',
'sfSympalDataGridPlugin',
- 'sfSympalUserPlugin',
'sfSympalInstallPlugin',
'sfSympalUpgradePlugin',
'sfSympalRenderingPlugin',
'sfSympalAdminPlugin',
'sfSympalFrontendEditorPlugin',
'sfSympalAssetsPlugin',
- 'sfSympalPlugin'
);
$t->is($sympalConfiguration->getRequiredPlugins(), $requiredPlugins);
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.