[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * This file is part of the symfony package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 pake_desc('install a new plugin'); 12 pake_task('plugin-install', 'project_exists'); 13 14 pake_desc('upgrade a plugin'); 15 pake_task('plugin-upgrade', 'project_exists'); 16 17 pake_desc('uninstall a plugin'); 18 pake_task('plugin-uninstall', 'project_exists'); 19 20 pake_desc('list installed plugins'); 21 pake_task('plugin-list', 'project_exists'); 22 23 // symfony plugin-install pluginName 24 function run_plugin_install($task, $args) 25 { 26 if (!isset($args[0])) 27 { 28 throw new Exception('You must provide the plugin name.'); 29 } 30 31 $config = _pear_init(); 32 33 // install plugin 34 $packages = array($args[0]); 35 pake_echo_action('plugin', 'installing plugin "'.$args[0].'"'); 36 list($ret, $error) = _pear_run_command($config, 'install', array(), $packages); 37 38 if ($error) 39 { 40 throw new Exception($error); 41 } 42 43 _install_web_content(_get_plugin_name($args[0])); 44 } 45 46 function run_plugin_upgrade($task, $args) 47 { 48 if (!isset($args[0])) 49 { 50 throw new Exception('You must provide the plugin name.'); 51 } 52 53 $config = _pear_init(); 54 55 // upgrade plugin 56 $packages = array($args[0]); 57 pake_echo_action('plugin', 'upgrading plugin "'.$args[0].'"'); 58 list($ret, $error) = _pear_run_command($config, 'upgrade', array('loose' => true, 'nodeps' => true), $packages); 59 60 if ($error) 61 { 62 throw new Exception($error); 63 } 64 65 $plugin_name = _get_plugin_name($args[0]); 66 _uninstall_web_content($plugin_name); 67 _install_web_content($plugin_name); 68 } 69 70 function run_plugin_uninstall($task, $args) 71 { 72 if (!isset($args[0])) 73 { 74 throw new Exception('You must provide the plugin name.'); 75 } 76 77 _uninstall_web_content(_get_plugin_name($args[0])); 78 79 $config = _pear_init(); 80 81 // uninstall plugin 82 $packages = array($args[0]); 83 pake_echo_action('plugin', 'uninstalling plugin "'.$args[0].'"'); 84 list($ret, $error) = _pear_run_command($config, 'uninstall', array(), $packages); 85 86 if ($error) 87 { 88 throw new Exception($error); 89 } 90 } 91 92 function run_plugin_list($task, $args) 93 { 94 pake_echo('Installed plugins:'); 95 96 $config = _pear_init(); 97 $registry = $config->getRegistry(); 98 $installed = $registry->packageInfo(null, null, null); 99 foreach ($installed as $channel => $packages) 100 { 101 foreach ($packages as $package) 102 { 103 $pobj = $registry->getPackage(isset($package['package']) ? $package['package'] : $package['name'], $channel); 104 pake_echo(sprintf(" %-40s %10s-%-6s %s", pakeColor::colorize($pobj->getPackage(), 'INFO'), $pobj->getVersion(), $pobj->getState() ? $pobj->getState() : null, pakeColor::colorize(sprintf('# %s (%s)', $channel, $registry->getChannel($channel)->getAlias()), 'COMMENT'))); 105 } 106 } 107 } 108 109 function _pear_run_command($config, $command, $opts, $params) 110 { 111 ob_start('_pear_echo_message', 2); 112 $cmd = PEAR_Command::factory($command, $config); 113 $ret = ob_get_clean(); 114 if (PEAR::isError($cmd)) 115 { 116 throw new Exception($cmd->getMessage()); 117 } 118 119 ob_start('_pear_echo_message', 2); 120 $ok = $cmd->run($command, $opts, $params); 121 $ret .= ob_get_clean(); 122 123 $ret = trim($ret); 124 125 return PEAR::isError($ok) ? array($ret, $ok->getMessage()) : array($ret, null); 126 } 127 128 function _pear_echo_message($message) 129 { 130 $t = ''; 131 foreach (explode("\n", $message) as $longline) 132 { 133 foreach (explode("\n", wordwrap($longline, 62)) as $line) 134 { 135 if ($line = trim($line)) 136 { 137 $t .= pake_format_action('pear', $line); 138 } 139 } 140 } 141 142 return $t; 143 } 144 145 function _pear_init() 146 { 147 require_once 'PEAR.php'; 148 require_once 'PEAR/Frontend.php'; 149 require_once 'PEAR/Config.php'; 150 require_once 'PEAR/Registry.php'; 151 require_once 'PEAR/Command.php'; 152 require_once 'PEAR/Remote.php'; 153 154 // current symfony release 155 $sf_version = preg_replace('/\-\w+$/', '', file_get_contents(sfConfig::get('sf_symfony_lib_dir').'/VERSION')); 156 157 // PEAR 158 PEAR_Command::setFrontendType('CLI'); 159 $ui = &PEAR_Command::getFrontendObject(); 160 161 // read user/system configuration (don't use the singleton) 162 $config = new PEAR_Config(); 163 $config_file = sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'.pearrc'; 164 165 // change the configuration for symfony use 166 $config->set('php_dir', sfConfig::get('sf_plugins_dir')); 167 $config->set('data_dir', sfConfig::get('sf_plugins_dir')); 168 $config->set('test_dir', sfConfig::get('sf_plugins_dir')); 169 $config->set('doc_dir', sfConfig::get('sf_plugins_dir')); 170 $config->set('bin_dir', sfConfig::get('sf_plugins_dir')); 171 172 // change the PEAR temp dir 173 $config->set('cache_dir', sfConfig::get('sf_cache_dir')); 174 $config->set('download_dir', sfConfig::get('sf_cache_dir')); 175 $config->set('tmp_dir', sfConfig::get('sf_cache_dir')); 176 177 // save out configuration file 178 $config->writeConfigFile($config_file, 'user'); 179 180 // use our configuration file 181 $config = &PEAR_Config::singleton($config_file); 182 183 $config->set('verbose', 1); 184 $ui->setConfig($config); 185 186 date_default_timezone_set('UTC'); 187 188 // register our channel 189 $symfony_channel = array( 190 'attribs' => array( 191 'version' => '1.0', 192 'xmlns' => 'http://pear.php.net/channel-1.0', 193 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 194 'xsi:schemaLocation' => 'http://pear.php.net/dtd/channel-1.0 http://pear.php.net/dtd/channel-1.0.xsd', 195 ), 196 197 'name' => 'pear.symfony-project.com', 198 'summary' => 'symfony project PEAR channel', 199 'suggestedalias' => 'symfony', 200 'servers' => array( 201 'primary' => array( 202 'rest' => array( 203 'baseurl' => array( 204 array( 205 'attribs' => array('type' => 'REST1.0'), 206 '_content' => 'http://pear.symfony-project.com/Chiara_PEAR_Server_REST/', 207 ), 208 array( 209 'attribs' => array('type' => 'REST1.1'), 210 '_content' => 'http://pear.symfony-project.com/Chiara_PEAR_Server_REST/', 211 ), 212 ), 213 ), 214 ), 215 ), 216 '_lastmodified' => array( 217 'ETag' => "113845-297-dc93f000", 218 'Last-Modified' => date('r'), 219 ), 220 ); 221 pake_mkdirs(sfConfig::get('sf_plugins_dir').'/.channels/.alias'); 222 file_put_contents(sfConfig::get('sf_plugins_dir').'/.channels/pear.symfony-project.com.reg', serialize($symfony_channel)); 223 file_put_contents(sfConfig::get('sf_plugins_dir').'/.channels/.alias/symfony.txt', 'pear.symfony-project.com'); 224 225 // register symfony for dependencies 226 $symfony = array( 227 'name' => 'symfony', 228 'channel' => 'pear.symfony-project.com', 229 'date' => date('Y-m-d'), 230 'time' => date('H:i:s'), 231 'version' => array('release' => $sf_version, 'api' => '1.0.0'), 232 'stability' => array('release' => 'stable', 'api' => 'stable'), 233 'xsdversion' => '2.0', 234 '_lastmodified' => time(), 235 'old' => array('version' => $sf_version, 'release_state' => 'stable'), 236 ); 237 $dir = sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'.registry'.DIRECTORY_SEPARATOR.'.channel.pear.symfony-project.com'; 238 pake_mkdirs($dir); 239 file_put_contents($dir.DIRECTORY_SEPARATOR.'symfony.reg', serialize($symfony)); 240 241 return $config; 242 } 243 244 function _get_plugin_name($arg) 245 { 246 $plugin_name = (false !== $pos = strrpos($arg, '/')) ? substr($arg, $pos + 1) : $arg; 247 $plugin_name = (false !== $pos = strrpos($plugin_name, '-')) ? substr($plugin_name, 0, $pos) : $plugin_name; 248 249 return $plugin_name; 250 } 251 252 function _install_web_content($plugin_name) 253 { 254 $web_dir = sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.$plugin_name.DIRECTORY_SEPARATOR.'web'; 255 if (is_dir($web_dir)) 256 { 257 pake_echo_action('plugin', 'installing web data for plugin'); 258 pake_symlink($web_dir, sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$plugin_name, true); 259 } 260 } 261 262 function _uninstall_web_content($plugin_name) 263 { 264 $web_dir = sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.$plugin_name.DIRECTORY_SEPARATOR.'web'; 265 $target_dir = sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.$plugin_name; 266 if (is_dir($web_dir) && is_dir($target_dir)) 267 { 268 pake_echo_action('plugin', 'uninstalling web data for plugin'); 269 if (is_link($target_dir)) 270 { 271 pake_remove($target_dir, ''); 272 } 273 else 274 { 275 pake_remove(pakeFinder::type('any'), $target_dir); 276 pake_remove($target_dir, ''); 277 } 278 } 279 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |