public function execute($arguments = array(), $options = array())
 {
     $projectDir = UtilPsdf::fixPath($arguments['pjpath']);
     $packagesDir = $projectDir . DIRECTORY_SEPARATOR . $arguments['pkpath'] . DIRECTORY_SEPARATOR;
     if (is_dir($projectDir)) {
         throw new sfCommandException(sprintf('The project "%s" already exists.', $projectDir));
     }
     $filesystem = new sfFilesystem();
     // Create basic workspace structure
     $skeletonDir = dirname(__FILE__) . '/../../data/generator/skeleton/psdfProject';
     $finder = sfFinder::type('any')->discard('.sf');
     $filesystem->mirror($skeletonDir, $projectDir, $finder);
     // Actualizo tokens
     $constants = array('PROJECT_NAME' => $arguments['pjname']);
     $finder = sfFinder::type('file')->name('.project');
     $filesystem->replaceTokens($finder->in($projectDir), '##', '##', $constants);
     // Create packages files (subdir por cada macro)
     $packages = $arguments['packages'];
     foreach ($packages as $pack) {
         if (!is_dir($packagesDir . $pack['macro'])) {
             $filesystem->mkdirs($packagesDir . $pack['macro']);
         }
         $file = $packagesDir . $pack['macro'] . DIRECTORY_SEPARATOR . $pack['name'] . '.xpdl';
         $filesystem->touch($file);
         file_put_contents($file, $pack['xpdl']);
     }
 }
Exemple #2
0
function refresh_assets()
{
    $uploadDir = dirname(__FILE__) . '/../fixtures/project/web/uploads';
    sfToolkit::clearDirectory($uploadDir);
    $finder = new sfFinder();
    $filesystem = new sfFilesystem();
    $filesystem->mirror(dirname(__FILE__) . '/../fixtures/assets', $uploadDir, $finder);
}
 private function copyWebAssets($plugin, $dir)
 {
     $webDir = $dir . DIRECTORY_SEPARATOR . 'web';
     $filesystem = new sfFilesystem();
     if (is_dir($webDir)) {
         $finder = sfFinder::type('any');
         $this->dirctoryRecusiveDelete(sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $plugin);
         $filesystem->mirror($webDir, sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $plugin, $finder);
     }
     return;
 }
Exemple #4
0
 public function _doUpgrade()
 {
     $this->logSection('sympal', 'Moving model/form/filter files from lib/*/doctrine/sfSympalPlugin to lib/*/doctrine/sfSympalCMFPlugin');
     $finder = sfFinder::type('file');
     $filesystem = new sfFilesystem($this->_dispatcher, $this->_formatter);
     foreach ($this->_dirs as $origin => $destination) {
         $this->logSection('sympal', sprintf('Mirroring %s to %s', $origin, $destination));
         $filesystem->mirror(sfConfig::get('sf_root_dir') . '/' . $origin, sfConfig::get('sf_root_dir') . '/' . $destination, $finder);
         $this->logSection('sympal', sprintf('Deleting %s', $origin));
         // remove the files first
         foreach ($finder->in(sfConfig::get('sf_root_dir') . '/' . $origin) as $file) {
             $filesystem->remove(sfConfig::get('sf_root_dir') . '/' . $origin . '/' . $file);
         }
         // remove the dirs
         $dirs = array(sfConfig::get('sf_root_dir') . '/' . $origin . '/base', sfConfig::get('sf_root_dir') . '/' . $origin);
         foreach ($dirs as $dir) {
             if (file_exists($dir)) {
                 $filesystem->remove($dir);
             }
         }
     }
 }
 /**
  * Validates the response.
  *
  * @param mixed $checkDTD Either true to validate against the response DTD or
  *                        provide the path to a *.xsd, *.rng or *.rnc schema
  *
  * @return sfTestFunctionalBase|sfTester
  *
  * @throws LogicException If the response is neither XML nor (X)HTML
  */
 public function isValid($checkDTD = false)
 {
     if (preg_match('/(x|ht)ml/i', $this->response->getContentType())) {
         $revert = libxml_use_internal_errors(true);
         $dom = new DOMDocument('1.0', $this->response->getCharset());
         $content = $this->response->getContent();
         if (true === $checkDTD) {
             $cache = sfConfig::get('sf_cache_dir') . '/sf_tester_response/w3';
             if ($cache[1] == ':') {
                 // On Windows systems the path will be like c:\symfony\cache\xml.dtd
                 // I did not manage to get DOMDocument loading a file protocol url including the drive letter
                 // file://c:\symfony\cache\xml.dtd or file://c:/symfony/cache/xml.dtd
                 // The first one simply doesnt work, the second one is treated as remote call.
                 // However the following works. Unfortunatly this means we can only access the current disk
                 // file:///symfony/cache/xml.dtd
                 // Note that all work for file_get_contents so the bug is most likely in DOMDocument.
                 $local = 'file://' . substr(str_replace(DIRECTORY_SEPARATOR, '/', $cache), 2);
             } else {
                 $local = 'file://' . $cache;
             }
             if (!file_exists($cache . '/TR/xhtml11/DTD/xhtml11.dtd')) {
                 $filesystem = new sfFilesystem();
                 $finder = sfFinder::type('any')->discard('.sf');
                 $filesystem->mirror(dirname(__FILE__) . '/w3', $cache, $finder);
                 $finder = sfFinder::type('file');
                 $filesystem->replaceTokens($finder->in($cache), '##', '##', array('LOCAL_W3' => $local));
             }
             $content = preg_replace('#(<!DOCTYPE[^>]+")http://www.w3.org(.*")#i', '\\1' . $local . '\\2', $content);
             $dom->validateOnParse = $checkDTD;
         }
         $dom->loadXML($content);
         switch (pathinfo($checkDTD, PATHINFO_EXTENSION)) {
             case 'xsd':
                 $dom->schemaValidate($checkDTD);
                 $message = sprintf('response validates per XSD schema "%s"', basename($checkDTD));
                 break;
             case 'rng':
             case 'rnc':
                 $dom->relaxNGValidate($checkDTD);
                 $message = sprintf('response validates per relaxNG schema "%s"', basename($checkDTD));
                 break;
             default:
                 $message = $dom->validateOnParse ? sprintf('response validates as "%s"', $dom->doctype->name) : 'response is well-formed "xml"';
         }
         if (count($errors = libxml_get_errors())) {
             foreach ($errors as $error) {
                 $message .= sprintf("\n * (line:%d) %s", $error->line, $error->message);
             }
             $this->tester->fail($message);
         } else {
             $this->tester->pass($message);
         }
         libxml_use_internal_errors($revert);
     } else {
         throw new LogicException(sprintf('Unable to validate responses of content type "%s"', $this->response->getContentType()));
     }
     return $this->getObjectToReturn();
 }
Exemple #6
0
 public function executeCollectAnonymousVisite(sfWebRequest $request)
 {
     $this->forward404unless($request->getParameter('visiteur_id') && $request->getParameter('visite_id'));
     $visiteur_id = $request->getParameter('visiteur_id');
     $visite_id = $request->getParameter('visite_id');
     $request->setRequestFormat('html');
     $serializer = $this->getSerializer();
     // check visiteur
     $visiteur = Doctrine_Query::create()->from('Visiteur')->where('guid = ?', $visiteur_id)->andWhereIn('is_anonyme', array(0, null))->limit(1)->execute();
     if (!$visiteur) {
         $this->getResponse()->setStatusCode(406);
         $result = array(array('message' => sprintf('visiteur %s not exist', $visiteur_id), 'code' => 'E_VISITEUR_00'));
         $this->output = $serializer->serialize($result, 'error');
         return sfView::SUCCESS;
     }
     // check visite
     $visite = Doctrine_Core::getTable('Visite')->findOneByGuid($visite_id);
     if (!$visite) {
         $this->getResponse()->setStatusCode(406);
         $result = array(array('message' => sprintf('visite %s not exist', $visite_id), 'code' => 'E_VISITE_00'));
         $this->output = $serializer->serialize($result, 'error');
         return sfView::SUCCESS;
     } else {
         $details = array();
         // get anonymous_visiteur
         $anonymous_visiteur_id = $visite->getVisiteurId();
         //$anonymous_visiteur_id->deleteActionFromCreateVisiteur();
         // already change
         if ($anonymous_visiteur_id == $visiteur_id) {
             $this->getResponse()->setStatusCode(406);
             $result = array(array('message' => 'visite already changed'));
             $this->output = $serializer->serialize($result, 'error');
             return sfView::SUCCESS;
         }
         // update Visite
         $visite->setVisiteurId($visiteur_id);
         $visite->save();
         // update LogVisite
         $log_visites = Doctrine_Core::getTable('LogVisite')->findByVisiteurId($anonymous_visiteur_id);
         $details['logVisite'] = count($log_visites);
         foreach ($log_visites as $log_visite) {
             $log_visite->setVisiteurId($visiteur_id);
             $log_visite->setVisiteId($visite_id);
             $log_visite->save();
         }
         // visiteur medaille
         $visiteur_medailles = Doctrine_Core::getTable('VisiteurMedaille')->findByVisiteurId($anonymous_visiteur_id);
         $details['VisiteurMedaille'] = count($visiteur_medailles);
         foreach ($visiteur_medailles as $visiteur_medaille) {
             $visiteur_medaille->setVisiteurId($visiteur_id);
             $visiteur_medaille->save();
         }
         // visiteur medaille
         $visiteur_univers = Doctrine_Core::getTable('VisiteurUniversStatusGain')->findByVisiteurId($anonymous_visiteur_id);
         $details['VisiteurUniversStatusGain'] = count($visiteur_univers);
         foreach ($visiteur_univers as $visiteur_univer) {
             $visiteur_univer->setVisiteurId($visiteur_id);
             $visiteur_univer->save();
         }
         // udate Xp
         $xps = Doctrine_Core::getTable('Xp')->findByVisiteurId($anonymous_visiteur_id);
         $details['Xp'] = count($xps);
         foreach ($xps as $xp) {
             $xp->setVisiteurId($visiteur_id);
             $xp->save();
         }
         // update Notification
         $notifications = Doctrine_Core::getTable('Notification')->findByVisiteurId($anonymous_visiteur_id);
         $details['Notification'] = count($notifications);
         foreach ($notifications as $notification) {
             $notification->setVisiteurId($visiteur_id);
             $notification->save();
         }
         $fileSystem = new sfFilesystem();
         $finder = new sfFinder();
         $path = sfConfig::get('sf_web_dir') . "/visiteur/" . $anonymous_visiteur_id;
         @$fileSystem->mirror(sfConfig::get('sf_web_dir') . "/visiteur/" . $anonymous_visiteur_id, sfConfig::get('sf_web_dir') . "/visiteur/" . $visiteur_id, $finder, array('override' => true));
         $result = array(array_merge(array('message' => 'ok'), array('details' => $details)));
         $this->output = $serializer->serialize($result, 'result');
         return sfView::SUCCESS;
     }
 }
Exemple #7
0
<?php

function sympal_cleanup()
{
    sfToolkit::clearDirectory(dirname(__FILE__) . '/../fixtures/project/cache');
    sfToolkit::clearDirectory(dirname(__FILE__) . '/../fixtures/project/log');
    @unlink(dirname(__FILE__) . '/../fixtures/project/data/test.sqlite');
}
copy(dirname(__FILE__) . '/../fixtures/project/data/fresh_test_db.sqlite', dirname(__FILE__) . '/../fixtures/project/data/test.sqlite');
copy(dirname(__FILE__) . '/../fixtures/project/config/fresh_app.yml', dirname(__FILE__) . '/../fixtures/project/config/app.yml');
register_shutdown_function('sympal_cleanup');
if (isset($refresh_assets) && $refresh_assets) {
    $uploadDir = dirname(__FILE__) . '/../fixtures/project/web/uploads';
    sfToolkit::clearDirectory($uploadDir);
    $finder = new sfFinder();
    $filesystem = new sfFilesystem();
    $filesystem->mirror(dirname(__FILE__) . '/../fixtures/assets', $uploadDir, $finder);
}
 private function mirrorDir($src, $dest)
 {
     $finder = sfFinder::type('any');
     $filesystem = new sfFilesystem();
     $filesystem->mirror($src, $dest, $finder, array('override' => true));
 }
 /**
  * Validates the response.
  *
  * @param mixed $checkDTD Either true to validate against the response DTD or
  *                        provide the path to a *.xsd, *.rng or *.rnc schema
  *
  * @return sfTestFunctionalBase|sfTester
  *
  * @throws LogicException If the response is neither XML nor (X)HTML
  */
 public function isValid($checkDTD = false)
 {
     if (preg_match('/(x|ht)ml/i', $this->response->getContentType())) {
         $revert = libxml_use_internal_errors(true);
         $dom = new DOMDocument('1.0', $this->response->getCharset());
         $content = $this->response->getContent();
         if (true === $checkDTD) {
             $cache = sfConfig::get('sf_cache_dir') . '/sf_tester_response/w3';
             $local = 'file://' . str_replace(DIRECTORY_SEPARATOR, '/', $cache);
             if (!file_exists($cache . '/TR/xhtml11/DTD/xhtml11.dtd')) {
                 $filesystem = new sfFilesystem();
                 $finder = sfFinder::type('any')->discard('.sf');
                 $filesystem->mirror(dirname(__FILE__) . '/w3', $cache, $finder);
                 $finder = sfFinder::type('file');
                 $filesystem->replaceTokens($finder->in($cache), '##', '##', array('LOCAL_W3' => $local));
             }
             $content = preg_replace('#(<!DOCTYPE[^>]+")http://www.w3.org(.*")#i', '\\1' . $local . '\\2', $content);
             $dom->validateOnParse = $checkDTD;
         }
         $dom->loadXML($content);
         switch (pathinfo($checkDTD, PATHINFO_EXTENSION)) {
             case 'xsd':
                 $dom->schemaValidate($checkDTD);
                 $message = sprintf('response validates per XSD schema "%s"', basename($checkDTD));
                 break;
             case 'rng':
             case 'rnc':
                 $dom->relaxNGValidate($checkDTD);
                 $message = sprintf('response validates per relaxNG schema "%s"', basename($checkDTD));
                 break;
             default:
                 $message = $dom->validateOnParse ? sprintf('response validates as "%s"', $dom->doctype->name) : 'response is well-formed "xml"';
         }
         if (count($errors = libxml_get_errors())) {
             $lines = explode(PHP_EOL, $this->response->getContent());
             $this->tester->fail($message);
             foreach ($errors as $error) {
                 $this->tester->diag('    ' . trim($error->message));
                 if (preg_match('/line (\\d+)/', $error->message, $match) && $error->line != $match[1]) {
                     $this->tester->diag('      ' . str_pad($match[1] . ':', 6) . trim($lines[$match[1] - 1]));
                 }
                 $this->tester->diag('      ' . str_pad($error->line . ':', 6) . trim($lines[$error->line - 1]));
             }
         } else {
             $this->tester->pass($message);
         }
         libxml_use_internal_errors($revert);
     } else {
         throw new LogicException(sprintf('Unable to validate responses of content type "%s"', $this->response->getContentType()));
     }
     return $this->getObjectToReturn();
 }
 protected function cleanupUploads(sfFilesystem $filesystem)
 {
     @sfToolkit::clearDirectory(sfConfig::get('sf_upload_dir'));
     $filesystem->mirror(dmOs::join(sfConfig::get('dm_core_dir'), 'test/fixtures/uploads'), sfConfig::get('sf_upload_dir'), sfFinder::type('any'));
 }
 private function mirrorDir($src, $dest)
 {
     $finder = sfFinder::type('any');
     $filesystem = new sfFilesystem();
     $filesystem->mirror($src, $dest, $finder);
 }
$this->logSection('install', 'fix sqlite database permissions');
touch(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR .'propel.db');
chmod(sfConfig::get('sf_data_dir'), 0777);
chmod(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'propel.db', 0777);


$this->logSection('install', 'install propel 1.6');
sfSymfonyPluginManager::disablePlugin('sfPropelPlugin', sfConfig::get('sf_config_dir'));
$fs->mkdirs(sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . 'sfPropelORMPlugin');

$root_dir = realpath(sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
$plugin_dir = realpath(sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . 'sfPropelORMPlugin');

$finder = sfFinder::type('any')->ignore_version_control(false)->discard('mockproject')->prune('mockproject');
$fs->mirror($root_dir, $plugin_dir, $finder);

$fs->execute(sprintf('cd %s && git submodule update --init --recursive', $plugin_dir));
sfSymfonyPluginManager::enablePlugin('sfPropelORMPlugin', sfConfig::get('sf_config_dir'));

$this->logSection('install', 'setup propel behavior');
$ini_file = sfConfig::get('sf_config_dir'). DIRECTORY_SEPARATOR . 'propel.ini';
$content = file_get_contents($ini_file);
preg_replace('#^propel.behavior#', ';\1', $content);
$content .= <<<EOF
propel.behavior.default                        = symfony,symfony_i18n
propel.behavior.symfony.class                  = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorSymfony
propel.behavior.symfony_i18n.class             = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorI18n
propel.behavior.symfony_i18n_translation.class = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorI18nTranslation
propel.behavior.symfony_behaviors.class        = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorSymfonyBehaviors
propel.behavior.symfony_timestampable.class    = plugins.sfPropelORMPlugin.lib.behavior.SfPropelBehaviorTimestampable
 protected function setUp()
 {
     $appConfig = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);
     sfContext::createInstance($appConfig);
     $this->cache = $this->getCache(sfConfig::get('sf_cache_dir') . '/sfImageTransformExtraPluginUnitTests');
     $fs = new sfFilesystem();
     $src_dir = dirname(__FILE__) . '/../../../fixtures/thumbnails';
     $dst_dir = $this->cache->getOption('cache_dir') . '/thumbnails';
     $fs->mirror($src_dir, $dst_dir, new sfFinder(), array('override' => true));
 }