public static function install_pear_package($package, $channel = 'pear.php.net') { if (!class_exists('PEAR_Config')) { @(include 'PEAR/Registry.php'); // loads config, among other things if (!class_exists('PEAR_Config')) { throw new pakeException('PEAR subsystem is unavailable (not in include_path?)'); } } $cfg = PEAR_Config::singleton(); $registry = $cfg->getRegistry(); // 1. check if package is installed if ($registry->_packageExists($package, $channel)) { return true; } $need_sudo = (!is_writable($cfg->get('download_dir')) or !is_writable($cfg->get('php_dir'))); // 2. if not installed, discover channel if (!$registry->_channelExists($channel, true)) { // sudo discover channel pake_echo_action('pear', 'discovering channel ' . $channel); if ($need_sudo) { pake_superuser_sh('pear channel-discover ' . escapeshellarg($channel)); } else { $this->nativePearDiscover($channel); } } // 3. install package pake_echo_action('pear', 'installing ' . $channel . '/' . $package); if ($need_sudo) { pake_superuser_sh('pear install ' . escapeshellarg($channel . '/' . $package), true); } else { $this->nativePearInstall($package, $channel); } }
function run_freeze($task, $args) { // check that the symfony librairies are not already freeze for this project if (is_readable(sfConfig::get('sf_lib_dir') . '/symfony')) { throw new Exception('You can only freeze when lib/symfony is empty.'); } if (is_readable(sfConfig::get('sf_data_dir') . '/symfony')) { throw new Exception('You can only freeze when data/symfony is empty.'); } if (is_readable(sfConfig::get('sf_web_dir') . '/sf')) { throw new Exception('You can only freeze when web/sf is empty.'); } if (is_link(sfConfig::get('sf_web_dir') . '/sf')) { pake_remove(sfConfig::get('sf_web_dir') . '/sf', ''); } $symfony_lib_dir = sfConfig::get('sf_symfony_lib_dir'); $symfony_data_dir = sfConfig::get('sf_symfony_data_dir'); pake_echo_action('freeze', 'freezing lib found in "' . $symfony_lib_dir . '"'); pake_echo_action('freeze', 'freezing data found in "' . $symfony_data_dir . '"'); pake_mkdirs(sfConfig::get('sf_lib_dir') . DIRECTORY_SEPARATOR . 'symfony'); pake_mkdirs(sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'symfony'); $finder = pakeFinder::type('any')->ignore_version_control(); pake_mirror($finder, $symfony_lib_dir, sfConfig::get('sf_lib_dir') . '/symfony'); pake_mirror($finder, $symfony_data_dir, sfConfig::get('sf_data_dir') . '/symfony'); pake_rename(sfConfig::get('sf_data_dir') . '/symfony/web/sf', sfConfig::get('sf_web_dir') . '/sf'); // change symfony paths in config/config.php file_put_contents('config/config.php.bak', "{$symfony_lib_dir}#{$symfony_data_dir}"); _change_symfony_dirs("dirname(__FILE__).'/../lib/symfony'", "dirname(__FILE__).'/../data/symfony'"); // install the command line pake_copy($symfony_data_dir . '/bin/symfony.php', 'symfony.php'); }
function run_tar($task, $args) { run_freeze($task, $args); pake_echo_action('tar', 'Making a tarball'); exec('PROJ=`pwd | awk \'BEGIN {FS="/"} {print $NF}\'`;cd ..; tar -czf $PROJ.tgz $PROJ --exclude=.svn --exclude=$PROJ/.* --exclude=$PROJ/log/* --exclude=$PROJ/cache/* ; cd $PROJ'); run_unfreeze($task, $args); }
function run_disallow_permissions() { $settings = getSettings(); $root = ".."; pake_echo_action("permissions", "allow permissions..."); pake_chmod('', $root, 0755); }
public static function emitFile($data, $file) { if (file_exists($file) and !is_writable($file)) { throw new pakeException('Not enough rights to overwrite "' . $file . '"'); } $dir = dirname($file); pake_mkdirs($dir); if (!is_writable($dir)) { throw new pakeException('Not enough rights to create file in "' . $dir . '"'); } if (extension_loaded('yaml')) { // not yet implemented: // yaml_emit_file($file, $data); // so using this instead: if (false === file_put_contents($file, yaml_emit($data))) { throw new pakeException("Couldn't create file"); } } else { sfYaml::setSpecVersion('1.1'); // more compatible $dumper = new sfYamlDumper(); if (false === file_put_contents($file, $dumper->dump($data, 1))) { throw new pakeException("Couldn't create file"); } } pake_echo_action('file+', $file); }
function run_propel_insert_sql_diff($task, $args) { run_propel_build_sql_diff($task, $args); $filename = sfConfig::get('sf_data_dir') . '/sql/diff.sql'; pake_echo_action('propel-sql-diff', "executing file {$filename}"); $i = new dbInfo(); $i->executeSql(file_get_contents($filename)); }
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)); } }
/** * To be able to include a plugin in pake_runtime.php, you have to use include_once for external dependencies * and require_once for internal dependencies (for other included PI or pake classes) because we strip * all require_once statements */ function run_compact($task, $args) { $_root = dirname(__FILE__); $options = pakeYaml::loadFile($_root . '/options.yaml'); $version = $options['version']; pake_replace_tokens('lib/pake/pakeApp.class.php', $_root, 'const VERSION = \'', '\';', array('1.1.DEV' => "const VERSION = '{$version}';")); // core-files $files = array($_root . '/lib/pake/init.php', $_root . '/lib/pake/pakeFunction.php'); // adding pake-classes library $files = array_merge($files, pakeFinder::type('file')->name('*.class.php')->maxdepth(0)->in($_root . '/lib/pake')); // adding sfYaml library $files = array_merge($files, pakeFinder::type('file')->name('*.php')->in($_root . '/lib/pake/sfYaml')); $plugins = $args; foreach ($plugins as $plugin_name) { $files[] = $_root . '/lib/pake/tasks/pake' . $plugin_name . 'Task.class.php'; } // starter $files[] = $_root . '/bin/pake.php'; // merge all files $content = ''; foreach ($files as $file) { $content .= file_get_contents($file); } pake_replace_tokens('lib/pake/pakeApp.class.php', $_root, "const VERSION = '", "';", array($version => "const VERSION = '1.1.DEV';")); // strip require_once statements $content = preg_replace('/^\\s*require(?:_once)?[^$;]+;/m', '', $content); // replace windows and mac format with unix format $content = str_replace(array("\r\n"), "\n", $content); // strip php tags $content = preg_replace(array("/<\\?php/", "/<\\?/", "/\\?>/"), '', $content); // replace multiple new lines with a single newline $content = preg_replace(array("/\n\\s+\n/s", "/\n+/s"), "\n", $content); $content = "#!/usr/bin/env php\n<?php\n" . trim($content) . "\n"; $target_dir = $_root . '/target'; pake_mkdirs($target_dir); $target = $target_dir . '/pake'; if (!file_put_contents($target, $content)) { throw new pakeException('Failed to write to "' . $target . '"'); } pake_echo_action('file+', $target); // strip all comments pake_strip_php_comments($target); pake_chmod('pake', $target_dir, 0755); }
private function sqlExec($sql) { if ($this->mode == 'pdo') { $this->db->exec($sql); pake_echo_action('pdo_mysql', $sql); } elseif ($this->mode == 'mysqli') { $result = $this->db->real_query($sql); if (false === $result) { throw new pakeException('MySQLi Error (' . $this->db->errno . ') ' . $this->db->error); } pake_echo_action('mysqli', $sql); } elseif ($this->mode == 'mysql') { $result = mysql_query($sql, $this->db); if (false === $result) { throw new pakeException('MySQL Error (' . mysql_errno() . ') ' . mysql_error()); } pake_echo_action('mysql', $sql); } }
function run_import_users($task, $args) { if (!isset($args[0])) { pake_echo_error('usage: pake i "users.yml"'); return false; } pake_echo_comment("Reading file. It can take awhile…"); $str = file_get_contents($args[0]); $data = pakeYaml::loadString($str); pake_echo_comment("Starting import…"); $len = count($data); for ($i = 0; $i < $len; $i++) { $row = $data[$i]; if (_create_user($row['login'], $row['password'], $row['data'])) { pake_echo_action('user+', "({$i} of {$len}) " . $row['login']); } else { pake_echo_comment('already exists: ' . "({$i} of {$len}) " . $row['login']); } } }
/** * execute HTTP Request * * @param string $method * @param string $url * @param mixed $query_data string or array * @param mixed $body string or array * @param array $headers * @param array $options * @return string */ public static function request($method, $url, $query_data = null, $body = null, array $headers = array(), array $options = array()) { $method = strtoupper($method); $_options = array('method' => $method, 'user_agent' => 'pake ' . pakeApp::VERSION, 'ignore_errors' => true); if (null !== $body) { if (is_array($body)) { $body = http_build_query($body); } $_options['content'] = $body; } if (count($headers) > 0) { $_options['header'] = implode("\r\n", $headers) . "\r\n"; } $options = array_merge($_options, $options); if (null !== $query_data) { if (is_array($query_data)) { $query_data = http_build_query($query_data); } $url .= '?' . $query_data; } $context = stream_context_create(array('http' => $options)); $stream = fopen($url, 'r', false, $context); if (false === $stream) { throw new pakeException('HTTP request failed'); } pake_echo_action('HTTP ' . $method, $url); $meta = stream_get_meta_data($stream); $response = stream_get_contents($stream); fclose($stream); $status = $meta['wrapper_data'][0]; $code = substr($status, 9, 3); if ($status > 400) { throw new pakeException('http request returned: ' . $status); } return $response; }
public static function run_app($task, $args) { if (isset($args[0])) { $config_file = $args[0]; } else { $config_file = getcwd() . '/config.yaml'; } pake_echo_comment('Loading configuration…'); if (!file_exists($config_file)) { throw new \pakeException("Configuration file is not found: " . $config_file); } $config = \pakeYaml::loadFile($config_file); $runner = new Runner(); foreach ($config['servers'] as $server) { if (!class_exists($server['app']['class'])) { require dirname($config_file) . '/' . $server['app']['file']; pake_echo_action('load class', $server['app']['class']); } $runner->addServer($server['app']['class'], $server['app']['middlewares'], $server['protocol'], $server['socket'], $server['min-children'], $server['max-children']); pake_echo_action('register', $server['app']['class'] . ' server via ' . $server['protocol'] . ' at ' . $server['socket'] . '. (' . $server['min-children'] . '-' . $server['max-children'] . ' children)'); } pake_echo_comment('Starting server…'); $runner->go(); }
protected function unrecordMigration($version) { $version = $this->cleanVersion($version); $this->executeUpdate("DELETE FROM schema_migration WHERE version='{$version}'"); pake_echo_action('migrations', "rollback version {$version}"); }
/** * Updates the "eZ CP version history" document, currently hosted on pubsvn.ez.no. * * Options: --public-keyfile=<...> --private-keyfile=<...> --user=<...> --private-keypasswd=<...> * * @todo add support for getting ssl certs options in config settings */ public static function run_update_version_history($task = null, $args = array(), $cliopts = array()) { $opts = self::getOpts($args, $cliopts); $public_keyfile = @$cliopts['public-keyfile']; $private_keyfile = @$cliopts['private-keyfile']; $private_keypasswd = @$cliopts['private-keypasswd']; $user = @$cliopts['user']; // get file $srv = "http://pubsvn.ez.no"; $filename = "/ezpublish_version_history/ez_history.csv"; $fullfilename = $srv . $filename; $remotefilename = '/mnt/pubsvn.ez.no/www/' . $filename; $file = pake_read_file($fullfilename); if ("" == $file) { throw new pakeException("Couldn't download {$fullfilename} file"); } // patch it /// @todo test that what we got looks at least a bit like what we expect $lines = preg_split("/\r?\n/", $file); $lines[0] .= $opts['version']['alias'] . ','; $lines[1] .= strftime('%Y/%m/%d') . ','; $file = implode("\n", $lines); /// @todo: back up the original as well (upload 1st to srv the unpatched version with a different name, then the new version) // upload it: we use curl for sftp $randfile = tempnam(sys_get_temp_dir(), 'EZP'); pake_write_file($randfile, $file, true); $fp = fopen($randfile, 'rb'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, str_replace('http://', 'sftp://@', $srv) . $remotefilename); if ($user != "") { curl_setopt($ch, CURLOPT_USERPWD, $user); } if ($public_keyfile != "") { curl_setopt($ch, CURLOPT_SSH_PUBLIC_KEYFILE, $public_keyfile); } if ($private_keyfile != "") { curl_setopt($ch, CURLOPT_SSH_PRIVATE_KEYFILE, $private_keyfile); } if ($private_keypasswd != "") { curl_setopt($ch, CURLOPT_KEYPASSWD, $private_keypasswd); } curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); // set size of the file, which isn't _mandatory_ but helps libcurl to do // extra error checking on the upload. curl_setopt($ch, CURLOPT_INFILESIZE, filesize($randfile)); $ok = curl_exec($ch); $errinfo = curl_error($ch); curl_close($ch); fclose($fp); pake_unlink($randfile); if (!$ok) { throw new pakeException("Couldn't write {$fullfilename} file: " . $errinfo); } pake_echo_action("file+", $filename); }
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, ''); } } }
function pake_write_file($fname, $contents, $overwrite = false) { if (false === $overwrite and file_exists($fname)) { throw new pakeException('File "' . $fname . '" already exists'); } $res = file_put_contents($fname, $contents, LOCK_EX); if ($res === false) { throw new pakeException("Couldn't write {$fname} file"); } pake_echo_action("file+", $fname); }
/** * 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); } }
/** * Creates an archive out of a directory. * * Uses command-lne tar as Zeta Cmponents do no compress well, and pake * relies on phar which is buggy/unstable on old php versions * * @param boolean $no_top_dir when set, $sourcedir directory is not packaged as top-level dir in archive * @todo for tar formats, fix the extra "." dir packaged */ static function archiveDir($sourcedir, $archivefile, $no_top_dir = false) { // please tar cmd on win - OH MY! $archivefile = str_replace('\\', '/', $archivefile); $sourcedir = str_replace('\\', '/', realpath($sourcedir)); if ($no_top_dir) { $srcdir = '.'; $workdir = $sourcedir; } else { $srcdir = basename($sourcedir); $workdir = dirname($sourcedir); } $archivedir = dirname($archivefile); $extra = ''; $tar = self::getTool('tar'); if (substr($archivefile, -7) == '.tar.gz' || substr($archivefile, -4) == '.tgz') { $cmd = "{$tar} -z -cvf"; $extra = "-C " . escapeshellarg($workdir); $workdir = $archivedir; $archivefile = basename($archivefile); } else { if (substr($archivefile, -8) == '.tar.bz2') { $cmd = "{$tar} -j -cvf"; $extra = "-C " . escapeshellarg($workdir); $workdir = $archivedir; $archivefile = basename($archivefile); } else { if (substr($archivefile, -4) == '.tar') { $cmd = "{$tar} -cvf"; $extra = "-C " . escapeshellarg($workdir); $workdir = $archivedir; $archivefile = basename($archivefile); } else { if (substr($archivefile, -4) == '.zip') { $zip = self::getTool('zip'); $cmd = "{$zip} -9 -r"; } else { throw new pakeException("Can not determine archive type from filename: {$archivefile}"); } } } } pake_sh(self::getCdCmd($workdir) . " && {$cmd} {$archivefile} {$extra} {$srcdir}"); pake_echo_action('file+', $archivefile); }
function run_disable($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'; if (!file_exists(sfConfig::get('sf_root_dir') . '/' . $lockFile)) { pake_touch(sfConfig::get('sf_root_dir') . '/' . $lockFile, '777'); pake_echo_action('enable', "{$app} [{$env}] has been DISABLED"); return; } pake_echo_action('enable', "{$app} [{$env}] is currently DISABLED"); return; }
function run_gearman_tasks() { pake_echo_action("gearman_tasks", "Gearman tasks completed"); }
function pake_sh($cmd, $interactive = false) { $verbose = pakeApp::get_instance()->get_verbose(); pake_echo_action('exec ', $cmd); if (false === $interactive) { ob_start(); } passthru($cmd . ' 2>&1', $return); if (false === $interactive) { $content = ob_get_clean(); if ($return > 0) { throw new pakeException(sprintf('Problem executing command %s', $verbose ? "\n" . $content : '')); } } else { if ($return > 0) { throw new pakeException('Problem executing command'); } } if (false === $interactive) { return $content; } }
public static function extractArchive($archive_file, $target_dir, $overwrite = false, $files = null) { if (!extension_loaded('phar')) { throw new pakeException(__CLASS__ . ' module requires "phar" extension'); } pake_mkdirs($target_dir); pake_echo_action('extract', $archive_file); $arc = new PharData($archive_file); $arc->extractTo($target_dir, $files, $overwrite); }
/** * loadDataFromArray * * @param mixed $data * @access public * @return void */ public function loadDataFromArray($data) { $pendingRelations = array(); if ($data === null) { // no data return; } // only for pake_echo_action require_once sfConfig::get('sf_symfony_lib_dir') . '/vendor/pake/pakeFunction.php'; foreach ($data as $class => $entries) { pake_echo_action('Filling', sprintf('class "%s"', $class) . "\t"); // fetch a table object $table = sfDoctrine::getTable($class, $this->connectionName); $colNames = array_keys($table->getColumns()); $tableName = $table->getTableName(); // relation fields $relations = $table->getRelations(); //echo "Class $class: ".implode(', ', array_keys($relations))."\n"; if ($this->deleteCurrentData) { $q = new Doctrine_Query(); $q->delete()->from($class); $q->execute(); } // iterate through entries for this class // might have been empty just for force a table to be emptied on import if (is_array($entries)) { foreach ($entries as $key => $columnAssignments) { // create a new entry in the database $obj = $table->create(); $now = date("Y-m-d H:i:s", time()); if ($obj->getTable()->hasColumn('created_at')) { $obj->set('created_at', $now); } if (!is_array($columnAssignments)) { throw new Exception('You must give a name for each fixture data entry'); } foreach ($columnAssignments as $name => $value) { $isRelation = isset($relations[$name]); // foreign key? if ($isRelation) { $rel = $relations[$name]; // $relatedTable = $rel->getTable()->getTableName(); $localKey = $rel->getLocal(); $foreignKey = $rel->getForeign(); $pendingRelations[] = array($obj, $localKey, $foreignKey, $value); } else { // first check that the column exists if (!in_array($name, $colNames)) { $error = 'Column "%s" does not exist for class "%s"'; $error = sprintf($error, $name, $class); throw new sfException($error); } $obj->rawSet($name, $value); } } $obj->save(); // For progress meter echo '.'; // save the id for future reference $pk = $obj->obtainIdentifier(); if (isset($this->object_references[$key])) { throw new sfException(sprintf('The key "%s" is not unique', $key)); } $this->object_references[$key] = $pk; } } echo "\n"; } // now we take care of the pending relations foreach ($pendingRelations as $pending) { list($obj, $localKey, $foreignKey, $key) = $pending; if (!isset($this->object_references[$key])) { $error = 'No object with key "%s" is defined in your data file'; $error = sprintf($error, $key); throw new sfException($error); } $foreignId = $this->object_references[$key][$foreignKey]; $obj->rawSet($localKey, $foreignId); $obj->save(); } }
private static function nativePearUpgrade($package, $channel) { pake_echo_action('pear', 'upgrading ' . $channel . '/' . $package); self::initPearClasses(); $front = PEAR_Frontend::singleton('PEAR_Frontend_CLI'); $cfg = PEAR_Config::singleton(); $cmd = PEAR_Command::factory('upgrade', $cfg); ob_start(); $result = $cmd->doInstall('upgrade', array(), array($channel . '/' . $package)); ob_end_clean(); // we don't need output if ($result instanceof PEAR_Error) { throw new pakeException($result->getMessage()); } }
function pake_sh($cmd) { $verbose = pakeApp::get_instance()->get_verbose(); pake_echo_action('exec ', $cmd); ob_start(); passthru($cmd . ' 2>&1', $return); $content = ob_get_contents(); ob_end_clean(); if ($return > 0) { throw new pakeException(sprintf('Problem executing command %s', $verbose ? "\n" . $content : '')); } return $content; }
public function execute($args, $options) { if ($this->dryrun) { pake_echo_action('execute', '(dry run) ' . $this->name); return; } if ($this->trace) { pake_echo_action('execute', $this->name); } // action to run $function = $this->get_alias() ? $this->get_alias() : $this->get_name(); if ($pos = strpos($function, '::')) { $function = array(substr($function, 0, $pos), preg_replace('/\\-/', '_', 'run_' . strtolower(substr($function, $pos + 2)))); if (!is_callable($function)) { throw new pakeException(sprintf('Task "%s" is defined but with no action defined.', $function[1])); } } else { $function = preg_replace('/\\-/', '_', 'run_' . strtolower($function)); if (!function_exists($function)) { throw new pakeException(sprintf('Task "%s" is defined but with no action defined.', $this->name)); } } // execute action return call_user_func_array($function, array($this, $args, $options)); }
/** * execute HTTP Request * * @param string $method * @param string $url * @param mixed $query_data string or array * @param mixed $body string or array * @param array $headers * @param array $options * @return string */ public static function request($method, $url, $query_data = null, $body = null, array $headers = array(), array $options = array()) { $method = strtoupper($method); $_options = array('method' => $method, 'user_agent' => 'pake ' . pakeApp::VERSION, 'ignore_errors' => true); $parsed_url = parse_url($url); $proxy_var_name = null; if ($parsed_url['scheme'] == 'http') { $proxy_var_name = 'http_proxy'; } elseif ($parsed_url['scheme'] == 'https') { if (isset($_SERVER['https_proxy'])) { $proxy_var_name = 'https_proxy'; } elseif (isset($_SERVER['HTTPS_PROXY'])) { $proxy_var_name = 'HTTPS_PROXY'; } } if (null !== $proxy_var_name) { if (isset($_SERVER[$proxy_var_name])) { $parsed_proxy_str = parse_url($_SERVER[$proxy_var_name]); if (is_array($parsed_proxy_str) and $parsed_proxy_str['scheme'] == 'http' and isset($parsed_proxy_str['host']) and isset($parsed_proxy_str['port'])) { $_options['proxy'] = 'tcp://' . $parsed_proxy_str['host'] . ':' . $parsed_proxy_str['port']; $_options['request_fulluri'] = true; pake_echo_comment('(using proxy: ' . $parsed_proxy_str['host'] . ':' . $parsed_proxy_str['port'] . ')'); } else { pake_echo_error('"' . $proxy_var_name . '" environment variable is set to the wrong value. expecting http://host:port'); } } } if (null !== $body) { if (is_array($body)) { $body = http_build_query($body); } $_options['content'] = $body; } if (count($headers) > 0) { $_options['header'] = implode("\r\n", $headers) . "\r\n"; } $options = array_merge($_options, $options); if (null !== $query_data) { if (is_array($query_data)) { $query_data = http_build_query($query_data); } $url .= '?' . $query_data; } $context = stream_context_create(array('http' => $options)); pake_echo_action('HTTP ' . $method, $url); $stream = @fopen($url, 'r', false, $context); if (false === $stream) { $err = error_get_last(); throw new pakeException('HTTP request failed: ' . $err['message']); } $meta = stream_get_meta_data($stream); $response = stream_get_contents($stream); fclose($stream); $status = $meta['wrapper_data'][0]; $code = substr($status, 9, 3); if ($code > 400) { throw new pakeException('http request returned: ' . $status); } pake_echo_action('…', 'got ' . strlen($response) . ' bytes'); return $response; }
public function execute($args, $options) { if ($this->dryrun) { pake_echo_action('execute', '(dry run) ' . $this->name); return; } if ($this->trace) { pake_echo_action('execute', $this->name); } // action to run $function = $this->getCallable(); // execute action return call_user_func_array($function, array($this, $args, $options)); }
/** * Generates the xml file listing all the files in the extension that is used as * part of an eZ Package description. * * This task is only run if in the configuration file package creation is specified. */ static function run_generate_package_filelist($task = null, $args = array(), $cliopts = array()) { $opts = self::getOpts(@$args[0], @$args[1], $cliopts); if ($opts['create']['ezpackage'] || $opts['create']['pearpackage']) { if (!SharedLock::acquire($opts['extension']['name'], LOCK_EX, $opts)) { throw new PakeException("Source code locked by another process"); } $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; $packageRoot = $doc->createElement('extension'); $packageRoot->setAttribute('name', $opts['extension']['name']); $rootpath = pakeFinder::type('directory')->name($opts['extension']['name'])->in(self::getBuildDir($opts)); $dirs = pakeFinder::type('directory')->in(self::getBuildDir($opts) . '/' . $opts['extension']['name']); foreach ($dirs as $dir) { $name = basename($dir); $path = dirname($dir); $path = str_replace(array($rootpath[0], '\\'), array('', '/'), $path); $fileNode = $doc->createElement('file'); $fileNode->setAttribute('name', $name); if ($path) { $fileNode->setAttribute('path', $path); } $fileNode->setAttribute('type', 'dir'); $packageRoot->appendChild($fileNode); } $files = pakeFinder::type('file')->in(self::getBuildDir($opts) . '/' . $opts['extension']['name']); foreach ($files as $file) { //$dir = ; $name = basename($file); $path = dirname($file); $path = str_replace(array($rootpath[0], '\\'), array('', '/'), $path); $fileNode = $doc->createElement('file'); $fileNode->setAttribute('name', $name); if ($path) { $fileNode->setAttribute('path', $path); } $fileNode->setAttribute('md5sum', md5_file($file)); $packageRoot->appendChild($fileNode); } $doc->appendChild($packageRoot); $doc->save(self::getBuildDir($opts) . '/extension-' . $opts['extension']['name'] . '.xml'); pake_echo_action('file+', self::getBuildDir($opts) . '/extension-' . $opts['extension']['name'] . '.xml'); SharedLock::release($opts['extension']['name'], LOCK_EX, $opts); } }
function _add_1_0_test_bootstraps() { pake_echo_action('upgrade 1.0', 'add test bootstrap files'); pake_mkdirs(sfConfig::get('sf_root_dir') . '/test/bootstrap'); pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/project/test/bootstrap/functional.php', sfConfig::get('sf_root_dir') . '/test/bootstrap/functional.php'); pake_copy(sfConfig::get('sf_symfony_data_dir') . '/skeleton/project/test/bootstrap/unit.php', sfConfig::get('sf_root_dir') . '/test/bootstrap/unit.php'); }