public function executeRun(sfWebRequest $request) { if (sfSympalConfig::get('installed')) { $this->redirect('@homepage'); } $this->setTemplate('index'); $this->form = new sfSympalInstallForm(); $this->form->bind($request->getParameter($this->form->getName())); $error = $this->getUser()->getFlash('error'); if ($error) { $this->getUser()->setFlash('error', $error); } if ($this->form->isValid() && !$error) { $values = $this->form->getValues(); $params = $values['user']; if ($values['database']['type']) { if ($values['database']['type'] == 'sqlite') { $params['db_dsn'] = 'sqlite:///' . $db['name']; } else { $params['db_dsn'] = $values['database']['type'] . '://' . $values['database']['username'] . ':' . $values['database']['password'] . '@' . $values['database']['host'] . '/' . $values['database']['name']; } $params['db_username'] = $values['database']['username']; $params['db_password'] = $values['database']['password']; } $formatter = new sfFormatter(); try { chdir(sfConfig::get('sf_root_dir')); $install = new sfSympalInstall($this->getContext()->getConfiguration(), $this->getContext()->getEventDispatcher(), $formatter); $install->setParams($params); $install->setOption('force_reinstall', true); $install->install(); } catch (Exception $e) { $this->getUser()->setFlash('error', $e->getMessage()); return sfView::SUCCESS; } $user = Doctrine_Core::getTable(sfSympalConfig::get('user_model'))->findOneByUsername($values['user']['username']); $this->getUser()->signin($user); if ($values['setup']['plugins']) { $plugins = $values['setup']['plugins']; foreach ($plugins as $plugin) { $manager = sfSympalPluginManager::getActionInstance($plugin, 'download', $this->getContext()->getConfiguration(), $formatter); $manager->download(); } $this->getUser()->setAttribute('sympal_install_plugins', $plugins); $this->redirect('@sympal_install_plugins'); } else { $this->getUser()->setFlash('notice', 'Sympal installed successfully!'); $this->redirect('@sympal_dashboard'); } } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $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; } $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']); } if (isset($options['last-name'])) { $install->setParam('last_name', $options['last-name']); } if (isset($options['db-dsn'])) { $install->setParam('db_dsn', $options['db-dsn']); } if (isset($options['db-username'])) { $install->setParam('db_username', $options['db-username']); } if (isset($options['db-password'])) { $install->setParam('db_password', $options['db-password']); } if (isset($options['force-reinstall']) && $options['force-reinstall']) { $install->setOption('force_reinstall', true); } $install->setOption('build_classes', (bool) $options['build-classes']); $install->install(); $this->log(null); $this->logSection('sympal', sprintf('Sympal was installed successfully...', $arguments['application']), null, 'COMMENT'); $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'); }