function setup() { if (!empty($this->data)) { $data = $this->data; $install_files_path = CONFIGS . 'install' . DS; $connection = array(); foreach (array('driver', 'host', 'login', 'password', 'database', 'prefix') as $k) { $connection[$k] = $data[$k]; } $this->_writeDBConfig($connection); uses('model' . DS . 'connection_manager'); $db = ConnectionManager::getInstance(); $connection = $db->getDataSource('default'); if ($connection->isConnected()) { App::import('vendor', 'migrations'); $oMigrations = new Migrations(); $oMigrations->load($install_files_path . 'schema.yml'); $dbRes = $oMigrations->up(); if (is_array($dbRes)) { $error_string = ''; foreach ($dbRes as $error) { $error_string .= $error['error'] . '<br />'; } $this->Session->setFlash(__('There were some errors during the creation of your db tables', true) . ':<br />' . $error_string); } elseif ($dbRes == true) { //add admin to the users table App::import('model', array('User', 'Site')); $User = new User(); $User->save(array('username' => $data['admin_username'], 'password' => sha1(Configure::read('Security.salt') . $data['admin_password']), 'group_id' => 1)); /*$Site = new Site(); $Site->save( array( 'user_id' => $User->getInsertID(), 'domain' => Configure::read( 'CMS.Site.Domain' ) ) );*/ App::import('vendor', 'fixtures'); $oFixtures = new Fixtures(); if ($oFixtures->import($install_files_path . 'fixtures.yml') === true) { $this->flash('Congratulations, you have successfully installed Pagebakery!', '/'); } else { $this->Session->setFlash(__('Sorry, there was an error adding initial data', true)); } } } else { $this->Session->setFlash('I could not connect to the DataBase. Please check the setup details again.'); } } $this->set('DBDrivers', $this->_getDBDrivers()); }
/** * Main method: Imports all fixtures from the fixtures path */ function main() { if (!class_exists('Spyc')) { $this->error('File not found', 'YAML class is needed for this shell to run. Could not be found - exiting.'); } $oFolder = new Folder(FIXTURES_PATH); $aFixtures = $oFolder->find('.+_fixture\\.yml'); $oFixtures = new Fixtures($this->sConnection); $iCount = 0; foreach ($aFixtures as $sFixture) { $iCount++; if ($oFixtures->import(FIXTURES_PATH . DS . $sFixture) !== true) { $this->error('Import failed.', 'Sorry, there was an error inserting the data into your database'); } else { $this->out('Importing ' . $sFixture . '...'); $this->out(''); } } $this->out($iCount . ' fixture(s) successfully imported'); }