function run_propel_init_admin($task, $args)
{
    if (count($args) < 2) {
        throw new Exception('You must provide your module name.');
    }
    if (count($args) < 3) {
        throw new Exception('You must provide your model class name.');
    }
    $app = $args[0];
    $module = $args[1];
    $model_class = $args[2];
    $theme = isset($args[3]) ? $args[3] : 'default';
    try {
        $author_name = $task->get_property('author', 'symfony');
    } catch (pakeException $e) {
        $author_name = 'Your name here';
    }
    $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name, 'THEME' => $theme);
    $moduleDir = sfConfig::get('sf_root_dir') . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module;
    // create module structure
    $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
    $dirs = sfLoader::getGeneratorSkeletonDirs('sfPropelAdmin', $theme);
    foreach ($dirs as $dir) {
        if (is_dir($dir)) {
            pake_mirror($finder, $dir, $moduleDir);
            break;
        }
    }
    // customize php and yml files
    $finder = pakeFinder::type('file')->ignore_version_control()->name('*.php', '*.yml');
    pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
}
 public static function createPharArchive($arg, $origin_dir, $archive_file, $stub = null, $web_stub = null, $overwrite = false)
 {
     if (!extension_loaded('phar')) {
         throw new pakeException(__CLASS__ . ' module requires "phar" extension');
     }
     if (false === $overwrite and file_exists($archive_file)) {
         return true;
     }
     if (!self::endsWith($archive_file, '.phar')) {
         throw new pakeException("Archive must have .phar extension");
     }
     $files = pakeFinder::get_files_from_argument($arg, $origin_dir, true);
     pake_echo_action('file+', $archive_file);
     try {
         $arc = new Phar($archive_file);
         foreach ($files as $file) {
             $full_path = $origin_dir . '/' . $file;
             pake_echo_action('phar', '-> ' . $file);
             if (is_dir($full_path)) {
                 $arc->addEmptyDir($file);
             } else {
                 $arc->addFile($full_path, $file);
             }
         }
         if (null !== $stub) {
             pake_echo_action('phar', '[stub] ' . $stub . (null === $web_stub ? '' : ', ' . $web_stub));
             $arc->setStub($arc->createDefaultStub($stub, $web_stub));
         }
     } catch (PharException $e) {
         unset($arc);
         pake_remove($archive_file);
         throw $e;
     }
 }
 public static function register($dir, $ext)
 {
     if (!is_dir($dir)) {
         return;
     }
     foreach (pakeFinder::type('file')->name('*' . $ext)->ignore_version_control()->follow_link()->in($dir) as $file) {
         self::$class_paths[str_replace($ext, '', str_replace('.class', '', basename($file, $ext)))] = $file;
     }
 }
 public function add($files = null)
 {
     if (null === $files) {
         $files = array('--all');
     } else {
         $files = pakeFinder::get_files_from_argument($files, $this->repository_path, true);
     }
     $this->git_run('add ' . implode(' ', array_map('escapeshellarg', $files)));
     return $this;
 }
Example #5
0
 public static function sfDoctrineInitialize()
 {
     //FIXME: loading all the sfDoctrine directory is probably not needed
     $files = pakeFinder::type('file')->name('*.php')->ignore_version_control()->in(realpath(dirname(__FILE__) . '/../..'));
     foreach ($files as $file) {
         preg_match_all('~^\\s*(?:abstract\\s+|final\\s+)?(?:class|interface)\\s+(\\w+)~mi', file_get_contents($file), $classes);
         foreach ($classes[1] as $class) {
             self::$class_paths[$class] = $file;
         }
     }
 }
Example #6
0
 public static function call_simpletest($task, $type = 'text', $dirs = array())
 {
     // remove E_STRICT because simpletest is not E_STRICT compatible
     $old_error_reporting = error_reporting();
     $new_error_reporting = $old_error_reporting;
     if ($new_error_reporting & E_STRICT) {
         $new_error_reporting = $new_error_reporting ^ E_STRICT;
     }
     include_once 'simpletest/unit_tester.php';
     include_once 'simpletest/web_tester.php';
     if (!class_exists('TestSuite')) {
         throw new pakeException('You must install SimpleTest to use this task.');
     }
     require_once 'simpletest/reporter.php';
     require_once 'simpletest/mock_objects.php';
     set_include_path('test' . PATH_SEPARATOR . 'lib' . PATH_SEPARATOR . get_include_path());
     $base_test_dir = 'test';
     $test_dirs = array();
     // run tests only in these subdirectories
     if ($dirs) {
         foreach ($dirs as $dir) {
             $test_dirs[] = $base_test_dir . DIRECTORY_SEPARATOR . $dir;
         }
     } else {
         $test_dirs[] = $base_test_dir;
     }
     $test = new TestSuite('Test suite in (' . implode(', ', $test_dirs) . ')');
     $files = pakeFinder::type('file')->name('*Test.php')->in($test_dirs);
     if (count($files) > 0) {
         foreach ($files as $file) {
             $test->addFile($file);
         }
         ob_start();
         if ($type == 'html') {
             $result = $test->run(new HtmlReporter());
         } else {
             if ($type == 'xml') {
                 $result = $test->run(new XmlReporter());
             } else {
                 $result = $test->run(new TextReporter());
             }
         }
         $content = ob_get_contents();
         ob_end_clean();
         if ($task->is_verbose()) {
             echo $content;
         }
     } else {
         throw new pakeException('No test to run.');
     }
     error_reporting($old_error_reporting);
 }
 public function test_pake_replace_tokens_finder()
 {
     $test_file_names = array('file1.tpl', 'file2.tpl', 'file3.tpl');
     foreach ($test_file_names as $test_file_name) {
         file_put_contents($this->test_dir . DIRECTORY_SEPARATOR . $test_file_name, '{token} {token2}');
     }
     $files = pakeFinder::type('file')->relative()->in($this->test_dir);
     pake_replace_tokens($files, $this->test_dir, '{', '}', array('token' => 'hello', 'token2' => 'world'));
     foreach ($test_file_names as $test_file_name) {
         $test_file = $this->test_dir . DIRECTORY_SEPARATOR . $test_file_name;
         $replaced = file_get_contents($test_file);
         $this->assertEqual('hello world', $replaced);
     }
 }
/**
 * clears xml files in the cache
 *
 * @example symfony fb-clear-xml-cache
 * @example symfony cx
 *
 * @param object $task
 * @param array $args
 */
function run_fb_clear_xml_cache($task, $args)
{
    if (!file_exists('cache')) {
        throw new Exception('Cache directory does not exist.');
    }
    $xml_cache_dir = sfConfig::get('sf_root_cache_dir') . "/atti";
    // finder to remove all files in a cache directory
    $finder = pakeFinder::type('file')->ignore_version_control()->discard('.sf');
    foreach ($args as $id) {
        $finder = $finder->name($id . ".xml");
    }
    // actually do remove the files under xml_cache_dir
    pake_remove($finder, $xml_cache_dir);
}
 public static function export($src_url, $target_path)
 {
     if (count(pakeFinder::type('any')->in($target_path)) > 0) {
         throw new pakeException('"' . $target_path . '" directory is not empty. Can not export there');
     }
     pake_echo_action('svn export', $target_path);
     if (extension_loaded('svn')) {
         $result = svn_export($src_url, $target_path, false);
         if (false === $result) {
             throw new pakeException('Couldn\'t export "' . $src_url . '" repository');
         }
     } else {
         pake_sh(escapeshellarg(pake_which('svn')) . ' export ' . escapeshellarg($src_url) . ' ' . escapeshellarg($target_path));
     }
 }
function run_unfreeze($task, $args)
{
    // remove lib/symfony and data/symfony directories
    if (!is_dir('lib/symfony')) {
        throw new Exception('You can unfreeze only if you froze the symfony libraries before.');
    }
    $dirs = explode('#', file_get_contents('config/config.php.bak'));
    _change_symfony_dirs('\'' . $dirs[0] . '\'', '\'' . $dirs[1] . '\'');
    $finder = pakeFinder::type('any')->ignore_version_control();
    pake_remove($finder, sfConfig::get('sf_lib_dir') . '/symfony');
    pake_remove(sfConfig::get('sf_lib_dir') . '/symfony', '');
    pake_remove($finder, sfConfig::get('sf_data_dir') . '/symfony');
    pake_remove(sfConfig::get('sf_data_dir') . '/symfony', '');
    pake_remove('symfony.php', '');
    pake_remove($finder, sfConfig::get('sf_web_dir') . '/sf');
    pake_remove(sfConfig::get('sf_web_dir') . '/sf', '');
}
 public static function initialize($with_cache = true)
 {
     $tmp_dir = sfToolkit::getTmpDir();
     if (is_readable($tmp_dir . DIRECTORY_SEPARATOR . 'sf_autoload_paths.php')) {
         self::$class_paths = unserialize(file_get_contents($tmp_dir . DIRECTORY_SEPARATOR . 'sf_autoload_paths.php'));
     } else {
         $files = pakeFinder::type('file')->name('*.class.php')->ignore_version_control()->in(realpath(dirname(__FILE__) . '/../../lib'));
         self::$class_paths = array();
         foreach ($files as $file) {
             preg_match_all('~^\\s*(?:abstract\\s+|final\\s+)?(?:class|interface)\\s+(\\w+)~mi', file_get_contents($file), $classes);
             foreach ($classes[1] as $class) {
                 self::$class_paths[$class] = $file;
             }
         }
         if ($with_cache) {
             file_put_contents($tmp_dir . DIRECTORY_SEPARATOR . 'sf_autoload_paths.php', serialize(self::$class_paths));
         }
     }
 }
Example #12
0
function run_test_unit($task, $args)
{
    if (isset($args[0])) {
        foreach ($args as $path) {
            $files = pakeFinder::type('file')->ignore_version_control()->follow_link()->name(basename($path) . 'Test.php')->in(sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'unit' . DIRECTORY_SEPARATOR . dirname($path));
            foreach ($files as $file) {
                include $file;
            }
        }
    } else {
        require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/lime/lime.php';
        $h = new lime_harness(new lime_output_color());
        $h->base_dir = sfConfig::get('sf_test_dir') . '/unit';
        // register unit tests
        $finder = pakeFinder::type('file')->ignore_version_control()->follow_link()->name('*Test.php');
        $h->register($finder->in($h->base_dir));
        $h->run();
    }
}
function run_propel_generate_crud($task, $args)
{
    if (count($args) < 2) {
        throw new Exception('You must provide your module name.');
    }
    if (count($args) < 3) {
        throw new Exception('You must provide your model class name.');
    }
    $theme = isset($args[3]) ? $args[3] : 'default';
    $app = $args[0];
    $module = $args[1];
    $model_class = $args[2];
    $sf_root_dir = sfConfig::get('sf_root_dir');
    // generate module
    $tmp_dir = $sf_root_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true));
    sfConfig::set('sf_module_cache_dir', $tmp_dir);
    $generator_manager = new sfGeneratorManager();
    $generator_manager->initialize();
    $generator_manager->generate('sfPropelCrudGenerator', array('model_class' => $model_class, 'moduleName' => $module, 'theme' => $theme));
    $moduleDir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module;
    // copy our generated module
    $finder = pakeFinder::type('any');
    pake_mirror($finder, $tmp_dir . '/auto' . ucfirst($module), $moduleDir);
    // change module name
    pake_replace_tokens($moduleDir . '/actions/actions.class.php', getcwd(), '', '', array('auto' . ucfirst($module) => $module));
    try {
        $author_name = $task->get_property('author', 'symfony');
    } catch (pakeException $e) {
        $author_name = 'Your name here';
    }
    $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'MODEL_CLASS' => $model_class, 'AUTHOR_NAME' => $author_name);
    // customize php and yml files
    $finder = pakeFinder::type('file')->name('*.php', '*.yml');
    pake_replace_tokens($finder, $moduleDir, '##', '##', $constants);
    // create basic test
    pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/module/test/actionsTest.php', $sf_root_dir . '/test/functional/' . $app . '/' . $module . 'ActionsTest.php');
    // customize test file
    pake_replace_tokens($module . 'ActionsTest.php', $sf_root_dir . '/test/functional/' . $app, '##', '##', $constants);
    // delete temp files
    $finder = pakeFinder::type('any');
    pake_remove($finder, $tmp_dir);
}
 public static function call_simpletest(pakeTask $task, $type = 'text', $dirs = array())
 {
     if (!class_exists('TestSuite')) {
         throw new pakeException('You must install SimpleTest to use this task.');
     }
     SimpleTest::ignore('UnitTestCase');
     $base_test_dir = 'test';
     $test_dirs = array();
     // run tests only in these subdirectories
     if ($dirs) {
         foreach ($dirs as $dir) {
             $test_dirs[] = $base_test_dir . DIRECTORY_SEPARATOR . $dir;
         }
     } else {
         $test_dirs[] = $base_test_dir;
     }
     $files = pakeFinder::type('file')->name('*Test.php')->in($test_dirs);
     if (count($files) == 0) {
         throw new pakeException('No test to run.');
     }
     $test = new TestSuite('Test suite in (' . implode(', ', $test_dirs) . ')');
     foreach ($files as $file) {
         $test->addFile($file);
     }
     ob_start();
     if ($type == 'html') {
         $result = $test->run(new HtmlReporter());
     } else {
         if ($type == 'xml') {
             $result = $test->run(new XmlReporter());
         } else {
             $result = $test->run(new TextReporter());
         }
     }
     $content = ob_get_contents();
     ob_end_clean();
     if ($task->is_verbose()) {
         echo $content;
     }
 }
function set_database($task, $args)
{
    if (!count($args)) {
        throw new Exception('You must provide the app.');
    }
    $app = $args[0];
    if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
        throw new Exception('The app "' . $app . '" does not exist.');
    }
    if (count($args) > 1 && $args[count($args) - 1] == 'append') {
        array_pop($args);
        $delete = false;
    } else {
        $delete = true;
    }
    $env = empty($args[1]) ? 'test' : $args[1];
    // define constants
    define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
    define('SF_APP', $app);
    define('SF_ENVIRONMENT', $env);
    define('SF_DEBUG', true);
    // get configuration
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    if (count($args) == 1) {
        if (!($pluginDirs = glob(sfConfig::get('sf_root_dir') . '/plugins/*/data'))) {
            $pluginDirs = array();
        }
        $fixtures_dirs = pakeFinder::type('dir')->ignore_version_control()->name('fixtures')->in(array_merge($pluginDirs, array(sfConfig::get('sf_data_dir'))));
    } else {
        $fixtures_dirs = array_slice($args, 1);
    }
    $db = new sfDatabaseManager();
    $db->initialize();
    $db = $db->getDatabase('propel');
    $config = array('hostname' => $db->getParameter('hostspec'), 'database' => $db->getParameter('database'), 'username' => $db->getParameter('username'), 'password' => $db->getParameter('password'), 'mysql' => sfConfig::get('app_mysql_command'), 'mysqldump' => sfConfig::get('app_mysqldump_command'), 'backupPath' => SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . 'fixtures');
    $config['backupFilename'] = $config['database'] . '_dump.sql';
    $config['backupFile'] = $config['backupPath'] . DIRECTORY_SEPARATOR . $config['backupFilename'];
    return $config;
}
 public static function run_test($task)
 {
     $php_cgi = '';
     $_php_cgi = self::_get_php_executable() . '-cgi';
     if (file_exists($_php_cgi)) {
         $php_cgi = ' ' . escapeshellarg('TEST_PHP_CGI_EXECUTABLE=' . $_php_cgi);
     }
     pake_echo_comment('Running test-suite. This can take awhile…');
     pake_sh('make test NO_INTERACTION=1' . $php_cgi);
     pake_echo_comment('Done');
     $path = dirname(pakeApp::get_instance()->getPakefilePath()) . '/tests';
     $files = pakeFinder::type('file')->ignore_version_control()->relative()->name('*.diff')->in($path);
     if (count($files) == 0) {
         pake_echo('   All tests PASSed!');
         return;
     }
     pake_echo_error('Following tests FAILed:');
     foreach ($files as $file) {
         $phpt_file = substr($file, 0, -4) . 'phpt';
         $_lines = file($path . '/' . $phpt_file);
         $description = $_lines[1];
         unset($_lines);
         pake_echo('     ' . $phpt_file . ' (' . rtrim($description) . ')');
     }
 }
/**
 * Loads yml data from fixtures directory and inserts into database.
 *
 * @example symfony opp-load-fixtures frontend
 * @example symfony opp-load-fixtures frontend dev fixtures append
 *
 * @todo replace delete argument with flag -d
 *
 * @param object $task
 * @param array $args
 */
function run_opp_load_fixtures($task, $args)
{
    if (!count($args)) {
        throw new Exception('You must provide the app.');
    }
    $app = $args[0];
    if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
        throw new Exception('The app "' . $app . '" does not exist.');
    }
    if (count($args) > 1 && $args[count($args) - 1] == 'append') {
        array_pop($args);
        $delete = false;
    } else {
        $delete = true;
    }
    $env = empty($args[1]) ? 'dev' : $args[1];
    // define constants
    define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
    define('SF_APP', $app);
    define('SF_ENVIRONMENT', $env);
    define('SF_DEBUG', true);
    // get configuration
    require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
    if (count($args) == 1) {
        if (!($pluginDirs = glob(sfConfig::get('sf_root_dir') . '/plugins/*/data'))) {
            $pluginDirs = array();
        }
        $fixtures_dirs = pakeFinder::type('dir')->ignore_version_control()->name('fixtures')->in(array_merge($pluginDirs, array(sfConfig::get('sf_data_dir'))));
    } else {
        $fixtures_dirs = array_slice($args, 1);
    }
    $databaseManager = new sfDatabaseManager();
    $databaseManager->initialize();
    $data = new myPropelData();
    $data->setDeleteCurrentData($delete);
    foreach ($fixtures_dirs as $fixtures_dir) {
        if (!is_readable($fixtures_dir)) {
            continue;
        }
        pake_echo_action('propel', sprintf('load data from "%s"', $fixtures_dir));
        $data->loadData($fixtures_dir);
    }
}
Example #18
0
function run_init_module($task, $args)
{
    if (count($args) < 2) {
        throw new Exception('You must provide your module name.');
    }
    $app = $args[0];
    $module = $args[1];
    $sf_root_dir = sfConfig::get('sf_root_dir');
    $module_dir = $sf_root_dir . '/' . sfConfig::get('sf_apps_dir_name') . '/' . $app . '/' . sfConfig::get('sf_app_module_dir_name') . '/' . $module;
    if (is_dir($module_dir)) {
        throw new Exception(sprintf('The directory "%s" already exists.', $module_dir));
    }
    try {
        $author_name = $task->get_property('author', 'symfony');
    } catch (pakeException $e) {
        $author_name = 'Your name here';
    }
    $constants = array('PROJECT_NAME' => $task->get_property('name', 'symfony'), 'APP_NAME' => $app, 'MODULE_NAME' => $module, 'AUTHOR_NAME' => $author_name);
    if (is_readable(sfConfig::get('sf_data_dir') . '/skeleton/module')) {
        $sf_skeleton_dir = sfConfig::get('sf_data_dir') . '/skeleton/module';
    } else {
        $sf_skeleton_dir = sfConfig::get('sf_symfony_data_dir') . '/skeleton/module';
    }
    // create basic application structure
    $finder = pakeFinder::type('any')->ignore_version_control()->discard('.sf');
    pake_mirror($finder, $sf_skeleton_dir . '/module', $module_dir);
    // create basic test
    pake_copy($sf_skeleton_dir . '/test/actionsTest.php', $sf_root_dir . '/test/functional/' . $app . '/' . $module . 'ActionsTest.php');
    // customize test file
    pake_replace_tokens($module . 'ActionsTest.php', $sf_root_dir . '/test/functional/' . $app, '##', '##', $constants);
    // customize php and yml files
    $finder = pakeFinder::type('file')->name('*.php', '*.yml');
    pake_replace_tokens($finder, $module_dir, '##', '##', $constants);
}
Example #19
0
function pake_symlink($origin_dir, $target_dir, $copy_on_windows = false)
{
    if (!function_exists('symlink') && $copy_on_windows) {
        $finder = pakeFinder::type('any')->ignore_version_control();
        pake_mirror($finder, $origin_dir, $target_dir);
        return;
    }
    $ok = false;
    if (is_link($target_dir)) {
        if (readlink($target_dir) != $origin_dir) {
            unlink($target_dir);
        } else {
            $ok = true;
        }
    }
    if (!$ok) {
        pake_echo_action('link+', $target_dir);
        symlink($origin_dir, $target_dir);
    }
}
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 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__) . '/../../lib/vendor/lime/lime.php';
require_once dirname(__FILE__) . '/../../lib/vendor/pake/pakeFinder.class.php';
$h = new lime_harness(new lime_output_color());
$h->base_dir = realpath(dirname(__FILE__) . '/..');
// unit tests
$h->register_glob($h->base_dir . '/unit/*/*Test.php');
// functional tests
$h->register_glob($h->base_dir . '/functional/*Test.php');
$h->register_glob($h->base_dir . '/functional/*/*Test.php');
$c = new lime_coverage($h);
$c->extension = '.class.php';
$c->verbose = false;
$c->base_dir = realpath(dirname(__FILE__) . '/../../lib');
$finder = pakeFinder::type('file')->ignore_version_control()->name('*.php')->prune('vendor');
$c->register($finder->in($c->base_dir));
$c->run();
Example #21
0
function run_enable($task, $args)
{
    ini_set("memory_limit", "2048M");
    // handling two required arguments (application and environment)
    if (count($args) < 2) {
        throw new Exception('You must provide an environment for the application.');
    }
    $app = $args[0];
    $env = $args[1];
    $lockFile = $app . '_' . $env . '.clilock';
    $locks = pakeFinder::type('file')->prune('.svn')->discard('.svn')->maxdepth(0)->name($lockFile)->relative()->in('./');
    if (file_exists(sfConfig::get('sf_root_dir') . '/' . $lockFile)) {
        pake_remove($lockFile, '');
        run_clear_cache($task, array());
        pake_echo_action('enable', "{$app} [{$env}] has been ENABLED");
        return;
    }
    pake_echo_action('enable', "{$app} [{$env}] is currently ENABLED");
}
Example #22
0
function killWorker($id)
{
    $pid = (int) trim(file_get_contents(RUNTIME_PATH . getWorkerPidFile($id)));
    @exec("kill -9 {$pid}");
    $rule = pakeFinder::type('file')->name(getWorkerPidFile($id));
    pake_remove($rule, RUNTIME_PATH);
}
Example #23
0
function run_create_poedit_file($task, $args)
{
    // the environment for poedit always is Development
    define('G_ENVIRONMENT', G_DEV_ENV);
    //the output language .po file
    $lgOutId = isset($args[0]) ? $args[0] : 'en';
    $countryOutId = isset($args[1]) ? strtoupper($args[1]) : 'US';
    $verboseFlag = isset($args[2]) ? $args[2] == true : false;
    require_once "propel/Propel.php";
    require_once "classes/model/Translation.php";
    require_once "classes/model/Language.php";
    require_once "classes/model/IsoCountry.php";
    Propel::init(PATH_CORE . "config/databases.php");
    $configuration = Propel::getConfiguration();
    $connectionDSN = $configuration['datasources']['propel']['connection'];
    printf("using DSN Connection %s \n", pakeColor::colorize($connectionDSN, 'INFO'));
    printf("checking Language table \n");
    $c = new Criteria();
    $c->add(LanguagePeer::LAN_ENABLED, "1");
    $c->addor(LanguagePeer::LAN_ENABLED, "0");
    $languages = LanguagePeer::doSelect($c);
    $langs = array();
    $lgIndex = 0;
    $findLang = false;
    $langDir = 'english';
    $langId = 'en';
    foreach ($languages as $rowid => $row) {
        $lgIndex++;
        $langs[$row->getLanId()] = $row->getLanName();
        if ($lgOutId != '' && $lgOutId == $row->getLanId()) {
            $findLang = true;
            $langDir = strtolower($row->getLanName());
            $langId = $row->getLanId();
        }
    }
    printf("read %s entries from language table\n", pakeColor::colorize($lgIndex, 'INFO'));
    printf("checking iso_country table \n");
    $c = new Criteria();
    $c->add(IsoCountryPeer::IC_UID, NULL, Criteria::ISNOTNULL);
    $countries = IsoCountryPeer::doSelect($c);
    $countryIndex = 0;
    $findCountry = false;
    $countryDir = 'UNITED STATES';
    $countryId = 'US';
    foreach ($countries as $rowid => $row) {
        $countryIndex++;
        if ($countryOutId != '' && $countryOutId == $row->getICUid()) {
            $findCountry = true;
            $countryDir = strtoupper($row->getICName());
            $countryId = $row->getICUid();
        }
    }
    printf("read %s entries from iso_country table\n", pakeColor::colorize($countryIndex, 'INFO'));
    if ($findLang == false && $lgOutId != '') {
        printf("%s \n", pakeColor::colorize("'{$lgOutId}' is not a valid language ", 'ERROR'));
        die;
    } else {
        printf("language: %s\n", pakeColor::colorize($langDir, 'INFO'));
    }
    if ($findCountry == false && $countryOutId != '') {
        printf("%s \n", pakeColor::colorize("'{$countryOutId}' is not a valid country ", 'ERROR'));
        die;
    } else {
        printf("country: [%s] %s\n", pakeColor::colorize($countryId, 'INFO'), pakeColor::colorize($countryDir, 'INFO'));
    }
    if ($findCountry && $countryId != '') {
        $poeditOutFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . $langDir . PATH_SEP . MAIN_POFILE . '.' . $langId . '_' . $countryId . '.po';
    } else {
        $poeditOutFile = PATH_CORE . 'content' . PATH_SEP . 'translations' . PATH_SEP . $langDir . PATH_SEP . MAIN_POFILE . '.' . $langId . '.po';
    }
    printf("poedit file: %s\n", pakeColor::colorize($poeditOutFile, 'INFO'));
    $poeditOutPathInfo = pathinfo($poeditOutFile);
    G::verifyPath($poeditOutPathInfo['dirname'], true);
    $lf = "\n";
    $fp = fopen($poeditOutFile, 'w');
    fprintf($fp, "msgid \"\" \n");
    fprintf($fp, "msgstr \"\" \n");
    fprintf($fp, "\"Project-Id-Version: %s\\n\"\n", PO_SYSTEM_VERSION);
    fprintf($fp, "\"POT-Creation-Date: \\n\"\n");
    fprintf($fp, "\"PO-Revision-Date: %s \\n\"\n", date('Y-m-d H:i+0100'));
    fprintf($fp, "\"Last-Translator: Fernando Ontiveros<*****@*****.**>\\n\"\n");
    fprintf($fp, "\"Language-Team: Colosa Developers Team <*****@*****.**>\\n\"\n");
    fprintf($fp, "\"MIME-Version: 1.0 \\n\"\n");
    fprintf($fp, "\"Content-Type: text/plain; charset=utf-8 \\n\"\n");
    fprintf($fp, "\"Content-Transfer_Encoding: 8bit\\n\"\n");
    fprintf($fp, "\"X-Poedit-Language: %s\\n\"\n", ucwords($langDir));
    fprintf($fp, "\"X-Poedit-Country: %s\\n\"\n", $countryDir);
    fprintf($fp, "\"X-Poedit-SourceCharset: utf-8\\n\"\n");
    printf("checking translation table\n");
    $c = new Criteria();
    $c->add(TranslationPeer::TRN_LANG, "en");
    $translation = TranslationPeer::doSelect($c);
    $trIndex = 0;
    $trError = 0;
    $langIdOut = $langId;
    //the output language, later we'll include the country too.
    $arrayLabels = array();
    foreach ($translation as $rowid => $row) {
        $keyid = 'TRANSLATION/' . $row->getTrnCategory() . '/' . $row->getTrnId();
        if (trim($row->getTrnValue()) == '') {
            printf("warning the key %s is empty.\n", pakeColor::colorize($keyid, 'ERROR'));
            $trError++;
        } else {
            $trans = TranslationPeer::retrieveByPK($row->getTrnCategory(), $row->getTrnId(), $langIdOut);
            if (is_null($trans)) {
                $msgStr = $row->getTrnValue();
            } else {
                $msgStr = $trans->getTrnValue();
            }
            $msgid = $row->getTrnValue();
            if (in_array($msgid, $arrayLabels)) {
                $newMsgid = '[' . $row->getTrnCategory() . '/' . $row->getTrnId() . '] ' . $msgid;
                printf("duplicated key %s is renamed to %s.\n", pakeColor::colorize($msgid, 'ERROR'), pakeColor::colorize($newMsgid, 'INFO'));
                $trError++;
                $msgid = $newMsgid;
            }
            $arrayLabels[] = $msgid;
            sort($arrayLabels);
            $trIndex++;
            fprintf($fp, "\n");
            fprintf($fp, "#: %s \n", $keyid);
            //fprintf ( $fp, "#, php-format \n" );
            fprintf($fp, "# %s \n", strip_quotes($keyid));
            fprintf($fp, "msgid \"%s\" \n", strip_quotes($msgid));
            fprintf($fp, "msgstr \"%s\" \n", strip_quotes($msgStr));
        }
    }
    printf("checking xmlform\n");
    printf("using directory %s \n", pakeColor::colorize(PATH_XMLFORM, 'INFO'));
    G::LoadThirdParty('pear/json', 'class.json');
    G::LoadThirdParty('smarty/libs', 'Smarty.class');
    G::LoadSystem('xmlDocument');
    G::LoadSystem('xmlform');
    G::LoadSystem('xmlformExtension');
    G::LoadSystem('form');
    $langIdOut = $langId;
    //the output language, later we'll include the country too.
    $exceptionFields = array('javascript', 'hidden', 'phpvariable', 'private', 'toolbar', 'xmlmenu', 'toolbutton', 'cellmark', 'grid');
    $xmlfiles = pakeFinder::type('file')->name('*.xml')->in(PATH_XMLFORM);
    $xmlIndex = 0;
    $xmlError = 0;
    $fieldsIndexTotal = 0;
    $exceptIndexTotal = 0;
    foreach ($xmlfiles as $xmlfileComplete) {
        $xmlIndex++;
        $xmlfile = str_replace(PATH_XMLFORM, '', $xmlfileComplete);
        //english version of dynaform
        $form = new Form($xmlfile, '', 'en');
        $englishLabel = array();
        foreach ($form->fields as $nodeName => $node) {
            if (trim($node->label) != '') {
                $englishLabel[$node->name] = $node->label;
            }
        }
        unset($form->fields);
        unset($form->tree);
        unset($form);
        //in this second pass, we are getting the target language labels
        $form = new Form($xmlfile, '', $langIdOut);
        $fieldsIndex = 0;
        $exceptIndex = 0;
        foreach ($form->fields as $nodeName => $node) {
            if (is_object($node) && isset($englishLabel[$node->name])) {
                $msgid = trim($englishLabel[$node->name]);
                $node->label = trim(str_replace(chr(10), '', $node->label));
            } else {
                $msgid = '';
            }
            if (trim($msgid) != '' && !in_array($node->type, $exceptionFields)) {
                //$msgid = $englishLabel [ $node->name ];
                $keyid = $xmlfile . '?' . $node->name;
                if (in_array($msgid, $arrayLabels)) {
                    $newMsgid = '[' . $keyid . '] ' . $msgid;
                    if ($verboseFlag) {
                        printf("duplicated key %s is renamed to %s.\n", pakeColor::colorize($msgid, 'ERROR'), pakeColor::colorize($newMsgid, 'INFO'));
                    }
                    $xmlError++;
                    $msgid = $newMsgid;
                }
                $arrayLabels[] = $msgid;
                sort($arrayLabels);
                $comment1 = $xmlfile;
                $comment2 = $node->type . ' - ' . $node->name;
                fprintf($fp, "\n");
                fprintf($fp, "#: %s \n", $keyid);
                //        fprintf ( $fp, "#, php-format \n" );
                fprintf($fp, "# %s \n", strip_quotes($comment1));
                fprintf($fp, "# %s \n", strip_quotes($comment2));
                fprintf($fp, "msgid \"%s\" \n", strip_quotes($msgid));
                fprintf($fp, "msgstr \"%s\" \n", strip_quotes($node->label));
                //fprintf ( $fp, "msgstr \"%s\" \n",  strip_quotes( utf8_encode( trim($node->label) ) ));
                $fieldsIndex++;
                $fieldsIndexTotal++;
            } else {
                if (is_object($node) && !in_array($node->type, $exceptionFields)) {
                    if (isset($node->value) && strpos($node->value, 'G::LoadTranslation') !== false) {
                        $exceptIndex++;
                        //print ($node->value);
                    } else {
                        printf("Error: xmlform %s has no english definition for %s [%s]\n", pakeColor::colorize($xmlfile, 'ERROR'), pakeColor::colorize($node->name, 'INFO'), pakeColor::colorize($node->type, 'INFO'));
                        $xmlError++;
                    }
                } else {
                    $exceptIndex++;
                    if ($verboseFlag) {
                        printf("%s %s in %s\n", $node->type, pakeColor::colorize($node->name, 'INFO'), pakeColor::colorize($xmlfile, 'INFO'));
                    }
                }
            }
        }
        unset($form->fields);
        unset($form->tree);
        unset($form);
        printf("xmlform: %s has %s fields and %s exceptions \n", pakeColor::colorize($xmlfile, 'INFO'), pakeColor::colorize($fieldsIndex, 'INFO'), pakeColor::colorize($exceptIndex, 'INFO'));
        $exceptIndexTotal += $exceptIndex;
    }
    fclose($fp);
    printf("added %s entries from translation table\n", pakeColor::colorize($trIndex, 'INFO'));
    printf("added %s entries from %s xmlforms  \n", pakeColor::colorize($fieldsIndexTotal, 'INFO'), pakeColor::colorize($xmlIndex, 'INFO'));
    if ($trError > 0) {
        printf("there are %s errors in tranlation table\n", pakeColor::colorize($trError, 'ERROR'));
    }
    if ($xmlError > 0) {
        printf("there are %s errors and %s exceptions in xmlforms\n", pakeColor::colorize($xmlError, 'ERROR'), pakeColor::colorize($exceptIndexTotal, 'ERROR'));
    }
    exit(0);
    //to do: leer los html templates
}
Example #24
0
 /**
  * Creates the tarballs for a release
  */
 function run_dist($task = null, $args = array(), $cliOpts = array())
 {
     // copy workspace dir into dist dir, without git
     pake_mkdirs(Builder::distDir());
     $finder = pakeFinder::type('any')->ignore_version_control();
     pake_mirror($finder, realpath(Builder::workspaceDir()), realpath(Builder::distDir()));
     // remove unwanted files from dist dir
     // also: do we still need to run dos2unix?
     // create tarballs
     $cwd = getcwd();
     chdir(dirname(Builder::distDir()));
     foreach (Builder::distFiles() as $distFile) {
         // php can not really create good zip files via phar: they are not compressed!
         if (substr($distFile, -4) == '.zip') {
             $cmd = Builder::tool('zip');
             $extra = '-9 -r';
             pake_sh("{$cmd} {$distFile} {$extra} " . basename(Builder::distDir()));
         } else {
             $finder = pakeFinder::type('any')->pattern(basename(Builder::distDir()) . '/**');
             // see https://bugs.php.net/bug.php?id=58852
             $pharFile = str_replace(Builder::libVersion(), '_LIBVERSION_', $distFile);
             pakeArchive::createArchive($finder, '.', $pharFile);
             rename($pharFile, $distFile);
         }
     }
     chdir($cwd);
 }
Example #25
0
function _uninstall_web_content($plugin_name)
{
    $web_dir = sfConfig::get('sf_plugins_dir') . DIRECTORY_SEPARATOR . $plugin_name . DIRECTORY_SEPARATOR . 'web';
    $target_dir = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $plugin_name;
    if (is_dir($web_dir) && is_dir($target_dir)) {
        pake_echo_action('plugin', 'uninstalling web data for plugin');
        if (is_link($target_dir)) {
            pake_remove($target_dir, '');
        } else {
            pake_remove(pakeFinder::type('any'), $target_dir);
            pake_remove($target_dir, '');
        }
    }
}
Example #26
0
/**
 * create an executable PHAR-archive of Pake
 *
 * @return bool
 * @author Alexey Zakhlestin
 */
function run_phar()
{
    $finder = pakeFinder::type('any')->ignore_version_control()->name('phar-stub.php', '*.class.php', 'autoload.php', 'cli_init.php', 'pakeFunction.php', 'sfYaml*.php');
    pakeArchive::createPharArchive($finder, dirname(__FILE__), 'pake.phar', 'phar-stub.php', null, true);
}
Example #27
0
function pake_strip_php_comments($arg, $target_dir = '')
{
    /* T_ML_COMMENT does not exist in PHP 5.
     * The following three lines define it in order to
     * preserve backwards compatibility.
     *
     * The next two lines define the PHP 5-only T_DOC_COMMENT,
     * which we will mask as T_ML_COMMENT for PHP 4.
     */
    if (!defined('T_ML_COMMENT')) {
        define('T_ML_COMMENT', T_COMMENT);
    } else {
        if (!defined('T_DOC_COMMENT')) {
            define('T_DOC_COMMENT', T_ML_COMMENT);
        }
    }
    $files = pakeFinder::get_files_from_argument($arg, $target_dir);
    foreach ($files as $file) {
        if (!is_file($file)) {
            continue;
        }
        $source = file_get_contents($file);
        $output = '';
        $tokens = token_get_all($source);
        foreach ($tokens as $token) {
            if (is_string($token)) {
                // simple 1-character token
                $output .= $token;
            } else {
                // token array
                list($id, $text) = $token;
                switch ($id) {
                    case T_COMMENT:
                    case T_ML_COMMENT:
                        // we've defined this
                    // we've defined this
                    case T_DOC_COMMENT:
                        // and this
                        // no action on comments
                        break;
                    default:
                        // anything else -> output "as is"
                        $output .= $text;
                        break;
                }
            }
        }
        file_put_contents($file, $output);
    }
}
Example #28
0
$h->base_dir = realpath(dirname(__FILE__) . '/../../test');
// unit tests
$h->register_glob($h->base_dir . '/unit/*/*Test.php');
// functional tests
$h->register_glob($h->base_dir . '/functional/*Test.php');
$h->register_glob($h->base_dir . '/functional/*/*Test.php');
$ret = $h->run();
if (!$ret) {
    throw new Exception('Some tests failed. Release process aborted!');
}
if (is_file('package.xml')) {
    pake_remove('package.xml', getcwd());
}
pake_copy(getcwd() . '/package.xml.tmpl', getcwd() . '/package.xml');
// add class files
$finder = pakeFinder::type('file')->ignore_version_control()->relative();
$xml_classes = '';
$dirs = array('lib' => 'php', 'data' => 'data');
foreach ($dirs as $dir => $role) {
    $class_files = $finder->in($dir);
    foreach ($class_files as $file) {
        $xml_classes .= '<file role="' . $role . '" baseinstalldir="symfony" install-as="' . $file . '" name="' . $dir . '/' . $file . '" />' . "\n";
    }
}
// replace tokens
pake_replace_tokens('package.xml', getcwd(), '##', '##', array('SYMFONY_VERSION' => $version, 'CURRENT_DATE' => date('Y-m-d'), 'CLASS_FILES' => $xml_classes, 'STABILITY' => $stability));
$results = pake_sh('pear package');
echo $results;
pake_remove('package.xml', getcwd());
// copy .tgz as symfony-latest.tgz
pake_copy(getcwd() . '/symfony-' . $version . '.tgz', getcwd() . '/symfony-latest.tgz');
Example #29
0
function run_create_package_xml()
{
    $_root = dirname(__FILE__);
    $options = pakeYaml::loadFile($_root . '/options.yaml');
    $version = $options['version'];
    // create a pear package
    pake_echo_comment('creating PEAR package.xml for version "' . $version . '"');
    pake_copy($_root . '/package.xml.tmpl', $_root . '/package.xml', array('override' => true));
    // add class files
    $class_files = pakeFinder::type('file')->ignore_version_control()->not_name('/^pakeApp.class.php$/')->name('*.php')->maxdepth(0)->relative()->in($_root . '/lib/pake');
    $task_files = pakeFinder::type('file')->ignore_version_control()->name('*.php')->relative()->in($_root . '/lib/pake/tasks');
    $renames = '';
    $xml_classes = '';
    $task_classes = '';
    foreach ($class_files as $file) {
        $xml_classes .= '<file role="php" name="' . $file . '"/>' . "\n";
        $renames .= '<install as="pake/' . $file . '" name="lib/pake/' . $file . '"/>' . "\n";
    }
    foreach ($task_files as $file) {
        $task_classes .= '<file role="php" name="' . $file . '"/>' . "\n";
        $renames .= '<install as="pake/tasks/' . $file . '" name="lib/pake/tasks/' . $file . '"/>' . "\n";
    }
    // replace tokens
    pake_replace_tokens('package.xml', $_root, '##', '##', array('PAKE_VERSION' => $version, 'CURRENT_DATE' => date('Y-m-d'), 'CLASS_FILES' => $xml_classes, 'TASK_FILES' => $task_classes, 'RENAMES' => $renames));
}
Example #30
0
function _call_phing($task, $task_name, $check_schema = true)
{
    $schemas = pakeFinder::type('file')->name('*schema.xml')->relative()->follow_link()->in('config');
    if ($check_schema && !$schemas) {
        throw new Exception('You must create a schema.yml or schema.xml file.');
    }
    // call phing targets
    pake_import('Phing', false);
    if (false === strpos('propel-generator', get_include_path())) {
        set_include_path(sfConfig::get('sf_symfony_lib_dir') . '/vendor/propel-generator/classes' . PATH_SEPARATOR . get_include_path());
    }
    set_include_path(sfConfig::get('sf_root_dir') . PATH_SEPARATOR . get_include_path());
    // 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_root_dir') . '/config', 'build.properties' => 'propel.ini', 'propel.output.dir' => sfConfig::get('sf_root_dir'));
    pakePhingTask::call_phing($task, array($task_name), sfConfig::get('sf_symfony_lib_dir') . '/vendor/propel-generator/build.xml', $options);
    chdir(sfConfig::get('sf_root_dir'));
}