public function upgrade()
 {
     if (!in_array('sfPropelPlugin', $this->configuration->getPlugins())) {
         if (file_exists($file = sfConfig::get('sf_config_dir') . '/propel.ini')) {
             $this->getFilesystem()->remove($file);
         }
         return;
     }
     if (file_exists($old = sfConfig::get('sf_lib_dir') . '/filter/base/BaseFormFilterPropel.class.php') && !file_exists($new = sfConfig::get('sf_lib_dir') . '/filter/BaseFormFilterPropel.class.php')) {
         $this->getFilesystem()->rename($old, $new);
     }
     if (file_exists($file = sfConfig::get('sf_config_dir') . '/propel.ini')) {
         // use phing to parse propel.ini
         sfPhing::startup();
         $this->properties = new Properties();
         $this->properties->load(new PhingFile($file));
         $modified = $original = file_get_contents($file);
         $modified = $this->upgradePropelIni($modified, self::$removes, false);
         $modified = $this->upgradePropelIni($modified, self::$inserts, true);
         if ($original != $modified) {
             $this->logSection('propel', 'Upgrading ' . sfDebug::shortenFilePath($file));
             file_put_contents($file, $modified);
         }
     }
 }
 protected function callPhing($taskName, $checkSchema, $properties = array())
 {
     $schemas = sfFinder::type('file')->name('*schema.xml')->relative()->follow_link()->in(sfConfig::get('sf_config_dir'));
     if (self::CHECK_SCHEMA === $checkSchema && !$schemas) {
         throw new sfCommandException('You must create a schema.yml or schema.xml file.');
     }
     // Call phing targets
     sfToolkit::addIncludePath(array(sfConfig::get('sf_symfony_lib_dir'), sfConfig::get('sf_propel_generator_path', realpath(dirname(__FILE__) . '/../vendor/propel-generator/classes'))));
     $args = array();
     $bufferPhingOutput = null === $this->commandApplication || !$this->commandApplication->withTrace();
     $properties = array_merge(array('build.properties' => 'propel.ini', 'project.dir' => sfConfig::get('sf_config_dir'), 'propel.output.dir' => sfConfig::get('sf_root_dir')), $properties);
     foreach ($properties as $key => $value) {
         $args[] = "-D{$key}={$value}";
     }
     // Build file
     $args[] = '-f';
     $args[] = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'propel-generator' . DIRECTORY_SEPARATOR . 'build.xml');
     // Logger
     if (DIRECTORY_SEPARATOR != '\\' && (function_exists('posix_isatty') && @posix_isatty(STDOUT))) {
         $args[] = '-logger';
         $args[] = 'phing.listener.AnsiColorLogger';
     }
     // Add our listener to detect errors
     $args[] = '-listener';
     $args[] = 'sfPhingListener';
     // Add any arbitrary arguments last
     foreach ($this->additionalPhingArgs as $arg) {
         if (in_array($arg, array('verbose', 'debug'))) {
             $bufferPhingOutput = false;
         }
         $args[] = '-' . $arg;
     }
     $args[] = $taskName;
     // filter arguments through the event dispatcher
     $args = $this->dispatcher->filter(new sfEvent($this, 'propel.filter_phing_args'), $args)->getReturnValue();
     require_once dirname(__FILE__) . '/sfPhing.class.php';
     // enable output buffering
     Phing::setOutputStream(new OutputStream(fopen('php://output', 'w')));
     Phing::startup();
     Phing::setProperty('phing.home', getenv('PHING_HOME'));
     $this->logSection('propel', 'Running "' . $taskName . '" phing task');
     if ($bufferPhingOutput) {
         ob_start();
     }
     $m = new sfPhing();
     $m->execute($args);
     $m->runBuild();
     if ($bufferPhingOutput) {
         ob_end_clean();
     }
     chdir(sfConfig::get('sf_root_dir'));
     // any errors?
     $ret = true;
     if (sfPhingListener::hasErrors()) {
         $messages = array('Some problems occurred when executing the task:');
         foreach (sfPhingListener::getExceptions() as $exception) {
             $messages[] = '';
             $messages[] = preg_replace('/^.*build\\-propel\\.xml/', 'build-propel.xml', $exception->getMessage());
             $messages[] = '';
         }
         if (count(sfPhingListener::getErrors())) {
             $messages[] = 'If the exception message is not clear enough, read the output of the task for';
             $messages[] = 'more information';
         }
         $this->logBlock($messages, 'ERROR_LARGE');
         $ret = false;
     }
     return $ret;
 }
Exemple #3
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new lime_test(1);
// ::getPhingVersion()
$t->diag('::getPhingVersion()');
$t->is(sfPhing::getPhingVersion(), 'sfPhing', '::getPhingVersion() returns "sfPhing"');
 protected function callPhing($taskName, $checkSchema)
 {
     $schemas = sfFinder::type('file')->name('*schema.xml')->relative()->follow_link()->in('config');
     if (self::CHECK_SCHEMA === $checkSchema && !$schemas) {
         throw new sfCommandException('You must create a schema.yml or schema.xml file.');
     }
     // Call phing targets
     if (false === strpos('propel-generator', get_include_path())) {
         set_include_path(sfConfig::get('sf_symfony_lib_dir') . '/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes' . PATH_SEPARATOR . get_include_path());
     }
     set_include_path(sfConfig::get('sf_root_dir') . PATH_SEPARATOR . get_include_path());
     $args = array();
     // Needed to include the right Propel builders
     set_include_path(sfConfig::get('sf_symfony_lib_dir') . PATH_SEPARATOR . get_include_path());
     $options = array('project.dir' => sfConfig::get('sf_config_dir'), 'build.properties' => 'propel.ini', 'propel.output.dir' => sfConfig::get('sf_root_dir'));
     foreach ($options as $key => $value) {
         $args[] = "-D{$key}={$value}";
     }
     // Build file
     $args[] = '-f';
     $args[] = realpath(sfConfig::get('sf_symfony_lib_dir') . '/plugins/sfPropelPlugin/lib/vendor/propel-generator/build.xml');
     if (is_null($this->commandApplication) || !$this->commandApplication->isVerbose()) {
         $args[] = '-q';
     }
     if (!is_null($this->commandApplication) && $this->commandApplication->withTrace()) {
         $args[] = '-debug';
     }
     // Logger
     if (DIRECTORY_SEPARATOR != '\\' && (function_exists('posix_isatty') && @posix_isatty(STDOUT))) {
         $args[] = '-logger';
         $args[] = 'phing.listener.AnsiColorLogger';
     }
     $args[] = $taskName;
     require_once dirname(__FILE__) . '/sfPhing.class.php';
     Phing::startup();
     Phing::setProperty('phing.home', getenv('PHING_HOME'));
     $m = new sfPhing();
     $m->execute($args);
     $m->runBuild();
     chdir(sfConfig::get('sf_root_dir'));
 }