Exemplo n.º 1
0
 /**
  * Run propel phing commands
  *
  * @param string $cmd	phing target
  * @param string $output Log generated by propel-gen
  * @return bool Returns true if the propel-gen command was successful, false otherwise.
  */
 protected function doPropelGen($cmd = '', &$output = "")
 {
     $output = Curry_Backend_DatabaseHelper::propelGen($cmd);
     $success = Curry_Backend_DatabaseHelper::getPropelGenStatus($output);
     $this->beginDetails("Running propel-gen {$cmd}", $success ? self::MSG_SUCCESS : self::MSG_ERROR, !$success);
     $this->addMainContent('<pre class="console">' . Console::colorize($output) . '</pre>');
     $this->endDetails();
     return $success;
 }
Exemplo n.º 2
0
 protected function saveConnection($params, $propelConfig)
 {
     $success = true;
     // Get adapter configuration
     $adapter = null;
     switch ($params['adapter']) {
         case 'mysql':
             $adapter = 'mysql';
             $dsn = "mysql:host={$params['host']};dbname={$params['database']}";
             $username = strlen($params['user']) ? $params['user'] : null;
             $password = strlen($params['password']) ? $params['password'] : null;
             break;
         default:
             $this->addMessage("Adapter configuration not supported, please configure database settings manually.", self::MSG_ERROR);
             return false;
     }
     // Update runtime configuration
     $config = new \SimpleXMLElement(file_get_contents($propelConfig));
     $defaultDataSource = (string) $config->propel->datasources['default'];
     foreach ($config->propel->datasources->datasource as $datasource) {
         if ((string) $datasource['id'] == $defaultDataSource) {
             $datasource->adapter = $adapter;
             $datasource->connection->dsn = $dsn;
             $datasource->connection->user = $username;
             $datasource->connection->password = $password;
         }
     }
     $config = $config->asXML();
     // Write database configuration
     if (!@file_put_contents($propelConfig, $config)) {
         $this->addMessage('Failed to write propel build configuration, please make sure this is the content of ' . $propelConfig . ':', self::MSG_ERROR);
         $this->addMainContent('<pre>' . htmlspecialchars($config) . '</pre>');
         return false;
     }
     // Generate propel classes and configuration
     $content = \Curry_Backend_DatabaseHelper::propelGen('');
     if (!\Curry_Backend_DatabaseHelper::getPropelGenStatus($content)) {
         $this->addMessage('It seems there was an error when building propel', self::MSG_ERROR);
         $this->addMainContent('<pre class="console">' . Console::colorize($content) . '</pre>');
         return false;
     }
     // Initialize propel
     \Propel::init($this->app['propel.conf']);
     // Set database charset
     if ($params['set_charset']) {
         $con = \Propel::getConnection();
         $result = $con->exec('ALTER DATABASE ' . $params['database'] . ' CHARACTER SET utf8 COLLATE utf8_general_ci');
         if (!$result) {
             $this->addMessage('Unable to change database charset', self::MSG_WARNING);
             $success = false;
         }
     }
     // Create tables
     if ($params['create_tables']) {
         $content = \Curry_Backend_DatabaseHelper::propelGen('insert-sql');
         if (!\Curry_Backend_DatabaseHelper::getPropelGenStatus($content)) {
             $this->addMessage('It seems there was an error when creating database tables', self::MSG_ERROR);
             $this->addMainContent('<pre class="console">' . Console::colorize($content) . '</pre>');
             return false;
         }
     }
     return $success;
 }