function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null) { $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer); if (@file_exists($test[2])) { // configuration has already been installed, check for mods if (md5_file($test[2]) !== md5_file($test[3])) { // configuration has been modified, so save our version as // configfile-version $old = $test[2]; $test[2] .= '.new-' . $pkg->getVersion(); // backup original and re-install it PEAR::pushErrorHandling(PEAR_ERROR_RETURN); $tmpcfg = $this->config->get('temp_dir'); $newloc = System::mkdir(array('-p', $tmpcfg)); if (!$newloc) { // try temp_dir $newloc = System::mktemp(array('-d')); if (!$newloc || PEAR::isError($newloc)) { PEAR::popErrorHandling(); return PEAR::raiseError('Could not save existing configuration file ' . $old . ', unable to install. Please set temp_dir ' . 'configuration variable to a writeable location and try again'); } } else { $newloc = $tmpcfg; } if (!@copy($old, $newloc . DIRECTORY_SEPARATOR . 'savefile')) { PEAR::popErrorHandling(); return PEAR::raiseError('Could not save existing configuration file ' . $old . ', unable to install. Please set temp_dir ' . 'configuration variable to a writeable location and try again'); } PEAR::popErrorHandling(); $this->installer->addFileOperation('rename', array($newloc . DIRECTORY_SEPARATOR . 'savefile', $old, false)); $this->installer->addFileOperation('delete', array($newloc . DIRECTORY_SEPARATOR . 'savefile')); } } return $test; }
private function cache() { // is it a remote image? if ($this->is_remote()) { $path = $this->image_folder . '/imagecache/original'; $image_original_name = "{$path}/" . preg_replace('/\\W/i', '-', $this->image_src); if (!file_exists($image_original_name)) { //make sure the directory(s) exist System::mkdir($path); // download image copy($this->image_src, $image_original_name); } unset($path); } else { // $image_original_name = Route::get('media')->uri(array('file' => $this->image_src)); $image_original_name = Kohana::find_file('media', $this->image_src, FALSE); } //if image file not found stop here if (!$this->is_valid($image_original_name)) { return FALSE; } $this->resized_image = "{$this->image_folder}/imagecache/{$this->resize_type}/{$this->width}x{$this->height}/{$this->image_src}"; if (!file_exists($this->resized_image)) { //make sure the directory(s) exist $path = pathinfo($this->resized_image, PATHINFO_DIRNAME); System::mkdir($path); // Save the resized image to the public directory for future requests $image_function = $this->resize_type === 'crop' ? 'crop' : 'resize'; Image::factory($image_original_name)->{$image_function}($this->width, $this->height)->save($this->resized_image, 85); } return TRUE; }
/** * Creates a new entry in the langs_avail .ini file. * * @param array $langData language data * @param string $path path to gettext data dir * * @return mixed Returns true on success or PEAR_Error on failure. */ function addLang($langData, $path = null) { if (!isset($path) || !is_string($path)) { $path = $this->_domains[$this->options['default_domain']]; } $path .= '/' . $langData['lang_id'] . '/LC_MESSAGES'; if (!is_dir($path)) { include_once 'System.php'; if (!System::mkdir(array('-p', $path))) { return $this->raiseError(sprintf('Cannot create new language in path "%s"', $path), TRANSLATION2_ERROR_CANNOT_CREATE_DIR); } } return true; }
function saveCache($args, $data) { $id = md5(serialize($args)); $cachedir = $this->config->get('cache_dir'); if (!file_exists($cachedir)) { System::mkdir(array('-p', $cachedir)); } $filename = $cachedir . '/xmlrpc_cache_' . $id; $fp = @fopen($filename, "wb"); if ($fp) { fwrite($fp, serialize($data)); fclose($fp); } }
/** * Static file serving (CSS, JS, images, etc.) * * @uses Request::param * @uses Request::uri * @uses Kohana::find_file * @uses Response::check_cache * @uses Response::body * @uses Response::headers * @uses Response::status * @uses File::mime_by_ext * @uses File::getExt * @uses Config::get * @uses Log::add * @uses System::mkdir */ public function action_serve() { // Get file theme from the request $theme = $this->request->param('theme', FALSE); // Get the file path from the request $file = $this->request->param('file'); // Find the file extension $ext = File::getExt($file); // Remove the extension from the filename $file = substr($file, 0, -(strlen($ext) + 1)); if ($file_name = Kohana::find_file('media', $file, $ext)) { // Check if the browser sent an "if-none-match: <etag>" header, and tell if the file hasn't changed $this->response->check_cache(sha1($this->request->uri()) . filemtime($file_name), $this->request); // Send the file content as the response $this->response->body(file_get_contents($file_name)); // Set the proper headers to allow caching $this->response->headers('content-type', File::mime_by_ext($ext)); $this->response->headers('last-modified', date('r', filemtime($file_name))); // This is ignored by check_cache $this->response->headers('cache-control', 'public, max-age=2592000'); if (Config::get('media.cache', FALSE)) { // Set base path $path = Config::get('media.public_dir', 'media'); // Override path if we're in admin if ($theme) { $path = $path . DS . $theme; } // Save the contents to the public directory for future requests $public_path = $path . DS . $file . '.' . $ext; $directory = dirname($public_path); if (!is_dir($directory)) { // Recursively create the directories needed for the file System::mkdir($directory, 0777, TRUE); } file_put_contents($public_path, $this->response->body()); } } else { Log::error('Media controller error while loading file: :file', array(':file' => $file)); // Return a 404 status $this->response->status(404); } }
function doUpdate($command, $options, $params) { $tmpdir = $this->config->get('temp_dir'); if (!file_exists($tmpdir)) { require_once 'System.php'; PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $err = System::mkdir(array('-p', $tmpdir)); PEAR::staticPopErrorHandling(); if (PEAR::isError($err)) { return $this->raiseError('channel-add: temp_dir does not exist: "' . $tmpdir . '" - You can change this location with "pear config-set temp_dir"'); } } if (!is_writable($tmpdir)) { return $this->raiseError('channel-add: temp_dir is not writable: "' . $tmpdir . '" - You can change this location with "pear config-set temp_dir"'); } $reg =& $this->config->getRegistry(); if (sizeof($params) != 1) { return $this->raiseError("No channel file specified"); } $lastmodified = false; if ((!file_exists($params[0]) || is_dir($params[0])) && $reg->channelExists(strtolower($params[0]))) { $c = $reg->getChannel(strtolower($params[0])); if (PEAR::isError($c)) { return $this->raiseError($c); } $this->ui->outputData("Updating channel \"{$params['0']}\"", $command); $dl =& $this->getDownloader(array()); // if force is specified, use a timestamp of "1" to force retrieval $lastmodified = isset($options['force']) ? false : $c->lastModified(); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $contents = $dl->downloadHttp('http://' . $c->getName() . '/channel.xml', $this->ui, $tmpdir, null, $lastmodified); PEAR::staticPopErrorHandling(); if (PEAR::isError($contents)) { return $this->raiseError('Cannot retrieve channel.xml for channel "' . $c->getName() . '" (' . $contents->getMessage() . ')'); } list($contents, $lastmodified) = $contents; if (!$contents) { $this->ui->outputData("Channel \"{$params['0']}\" is up to date"); return; } $contents = implode('', file($contents)); if (!class_exists('PEAR_ChannelFile')) { require_once 'PEAR/ChannelFile.php'; } $channel = new PEAR_ChannelFile(); $channel->fromXmlString($contents); if (!$channel->getErrors()) { // security check: is the downloaded file for the channel we got it from? if (strtolower($channel->getName()) != strtolower($c->getName())) { if (isset($options['force'])) { $this->ui->log(0, 'WARNING: downloaded channel definition file' . ' for channel "' . $channel->getName() . '" from channel "' . strtolower($c->getName()) . '"'); } else { return $this->raiseError('ERROR: downloaded channel definition file' . ' for channel "' . $channel->getName() . '" from channel "' . strtolower($c->getName()) . '"'); } } } } else { if (strpos($params[0], '://')) { $dl =& $this->getDownloader(); PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $loc = $dl->downloadHttp($params[0], $this->ui, $tmpdir, null, $lastmodified); PEAR::staticPopErrorHandling(); if (PEAR::isError($loc)) { return $this->raiseError("Cannot open " . $params[0] . ' (' . $loc->getMessage() . ')'); } else { list($loc, $lastmodified) = $loc; $contents = implode('', file($loc)); } } else { $fp = false; if (file_exists($params[0])) { $fp = fopen($params[0], 'r'); } if (!$fp) { return $this->raiseError("Cannot open " . $params[0]); } $contents = ''; while (!feof($fp)) { $contents .= fread($fp, 1024); } fclose($fp); } if (!class_exists('PEAR_ChannelFile')) { require_once 'PEAR/ChannelFile.php'; } $channel = new PEAR_ChannelFile(); $channel->fromXmlString($contents); } $exit = false; if (count($errors = $channel->getErrors(true))) { foreach ($errors as $error) { $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message'])); if (!$exit) { $exit = $error['level'] == 'error' ? true : false; } } if ($exit) { return $this->raiseError('Invalid channel.xml file'); } } if (!$reg->channelExists($channel->getName())) { return $this->raiseError('Error: Channel "' . $channel->getName() . '" does not exist, use channel-add to add an entry'); } $ret = $reg->updateChannel($channel, $lastmodified); if (PEAR::isError($ret)) { return $ret; } if (!$ret) { return $this->raiseError('Updating Channel "' . $channel->getName() . '" in registry failed'); } $this->config->setChannels($reg->listChannels()); $this->config->writeConfigFile(); $this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded'); }
/** * compile the template * * @access public * @version 01/12/03 * @author Wolfram Kriesing <*****@*****.**> * @param string $file relative to the 'templateDir' which you set when calling the constructor * @return boolean true on success. (or string, if compileToString) PEAR_Error on failure.. */ function compile($file) { if (!$file) { return $this->raiseError('HTML_Template_Flexy::compile no file selected', HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS, HTML_TEMPLATE_FLEXY_ERROR_DIE); } if (!@$this->options['locale']) { $this->options['locale'] = 'en'; } //Remove the slash if there is one in front, just to be safe. $file = ltrim($file, DIRECTORY_SEPARATOR); if (strpos($file, '#')) { list($file, $this->options['output.block']) = explode('#', $file); } $parts = array(); $tmplDirUsed = false; // PART A mulitlanguage support: ( part B is gettext support in the engine..) // - user created language version of template. // - compile('abcdef.html') will check for compile('abcdef.en.html') // (eg. when locale=en) $this->currentTemplate = false; if (preg_match('/(.*)(\\.[a-z]+)$/i', $file, $parts)) { $newfile = $parts[1] . '.' . $this->options['locale'] . $parts[2]; foreach ($this->options['templateDir'] as $tmplDir) { if (@(!file_exists($tmplDir . DIRECTORY_SEPARATOR . $newfile))) { continue; } $file = $newfile; $this->currentTemplate = $tmplDir . DIRECTORY_SEPARATOR . $newfile; $tmplDirUsed = $tmplDir; } } // look in all the posible locations for the template directory.. if ($this->currentTemplate === false) { $dirs = array_unique($this->options['templateDir']); if ($this->options['templateDirOrder'] == 'reverse') { $dirs = array_reverse($dirs); } foreach ($dirs as $tmplDir) { if (!@file_exists($tmplDir . DIRECTORY_SEPARATOR . $file)) { continue; } if (!$this->options['multiSource'] && $this->currentTemplate !== false) { return $this->raiseError("You have more than one template Named {$file} in your paths, found in both" . "<BR>{$this->currentTemplate}<BR>{$tmplDir}" . DIRECTORY_SEPARATOR . $file, HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS, HTML_TEMPLATE_FLEXY_ERROR_DIE); } $this->currentTemplate = $tmplDir . DIRECTORY_SEPARATOR . $file; $tmplDirUsed = $tmplDir; } } if ($this->currentTemplate === false) { // check if the compile dir has been created return $this->raiseError("Could not find Template {$file} in any of the directories<br>" . implode("<BR>", $this->options['templateDir']), HTML_TEMPLATE_FLEXY_ERROR_INVALIDARGS, HTML_TEMPLATE_FLEXY_ERROR_DIE); } // Savant compatible compiler if (is_string($this->options['compiler']) && $this->options['compiler'] == 'Raw') { $this->compiledTemplate = $this->currentTemplate; $this->debug("Using Raw Compiler"); return true; } // now for the compile target //If you are working with mulitple source folders and $options['multiSource'] is set //the template folder will be: // compiled_tempaltes/{templatedir_basename}_{md5_of_dir}/ $compileSuffix = count($this->options['templateDir']) > 1 && $this->options['multiSource'] ? DIRECTORY_SEPARATOR . basename($tmplDirUsed) . '_' . md5($tmplDirUsed) : ''; $compileDest = isset($this->options['compileDir']) ? $this->options['compileDir'] : ''; $isTmp = false; // Use a default compile directory if one has not been set. if (!$compileDest) { // Use session.save_path + 'compiled_templates_' + md5(of sourcedir) $compileDest = ini_get('session.save_path') . DIRECTORY_SEPARATOR . 'flexy_compiled_templates'; if (!file_exists($compileDest)) { require_once 'System.php'; System::mkdir(array('-p', $compileDest)); } $isTmp = true; } // we generally just keep the directory structure as the application uses it, // so we dont get into conflict with names // if we have multi sources we do md5 the basedir.. $base = $compileDest . $compileSuffix . DIRECTORY_SEPARATOR . $file; $fullFile = $this->compiledTemplate = $base . '.' . $this->options['locale'] . '.php'; $this->getTextStringsFile = $base . '.gettext.serial'; $this->elementsFile = $base . '.elements.serial'; if (isset($this->options['output.block'])) { $this->compiledTemplate .= '#' . $this->options['output.block']; } if (!empty($this->options['dontCompile'])) { return true; } $recompile = false; $isuptodate = file_exists($this->compiledTemplate) ? filemtime($this->currentTemplate) == filemtime($this->compiledTemplate) : 0; if (!empty($this->options['forceCompile']) || !$isuptodate) { $recompile = true; } else { $this->debug("File looks like it is uptodate."); return true; } if (!@is_dir($compileDest) || !is_writeable($compileDest)) { require_once 'System.php'; System::mkdir(array('-p', $compileDest)); } if (!@is_dir($compileDest) || !is_writeable($compileDest)) { return $this->raiseError("can not write to 'compileDir', which is <b>'{$compileDest}'</b><br>" . "Please give write and enter-rights to it", HTML_TEMPLATE_FLEXY_ERROR_FILE, HTML_TEMPLATE_FLEXY_ERROR_DIE); } if (!file_exists(dirname($this->compiledTemplate))) { require_once 'System.php'; System::mkdir(array('-p', '-m', 0770, dirname($this->compiledTemplate))); } // Compile the template in $file. require_once 'HTML/Template/Flexy/Compiler.php'; $compiler = HTML_Template_Flexy_Compiler::factory($this->options); $ret = $compiler->compile($this); if (HTML_Template_Flexy_is_a($ret, 'PEAR_Error')) { return $this->raiseError('HTML_Template_Flexy fatal error:' . $ret->message, $ret->code, HTML_TEMPLATE_FLEXY_ERROR_DIE); } return $ret; //return $this->$method(); }
function doBundle($command, $options, $params) { if (empty($this->installer)) { $this->installer =& new PEAR_Installer($this->ui); } $installer =& $this->installer; if (sizeof($params) < 1) { return $this->raiseError("Please supply the package you want to bundle"); } $pkgfile = $params[0]; $need_download = false; if (preg_match('#^(http|ftp)://#', $pkgfile)) { $need_download = true; } elseif (!@is_file($pkgfile)) { if ($installer->validPackageName($pkgfile)) { $pkgfile = $installer->getPackageDownloadUrl($pkgfile); $need_download = true; } else { if (strlen($pkgfile)) { return $this->raiseError("Could not open the package file: {$pkgfile}"); } else { return $this->raiseError("No package file given"); } } } // Download package ----------------------------------------------- if ($need_download) { $downloaddir = $installer->config->get('download_dir'); if (empty($downloaddir)) { if (PEAR::isError($downloaddir = System::mktemp('-d'))) { return $downloaddir; } $installer->log(2, '+ tmp dir created at ' . $downloaddir); } $callback = $this->ui ? array(&$installer, '_downloadCallback') : null; $file = $installer->downloadHttp($pkgfile, $this->ui, $downloaddir, $callback); if (PEAR::isError($file)) { return $this->raiseError($file); } $pkgfile = $file; } // Parse xml file ----------------------------------------------- $pkginfo = $installer->infoFromTgzFile($pkgfile); if (PEAR::isError($pkginfo)) { return $this->raiseError($pkginfo); } $installer->validatePackageInfo($pkginfo, $errors, $warnings); // XXX We allow warnings, do we have to do it? if (count($errors)) { if (empty($options['force'])) { return $this->raiseError("The following errors where found:\n" . implode("\n", $errors)); } else { $this->log(0, "warning : the following errors were found:\n" . implode("\n", $errors)); } } $pkgname = $pkginfo['package']; // Unpacking ------------------------------------------------- if (isset($options['destination'])) { if (!is_dir($options['destination'])) { System::mkdir('-p ' . $options['destination']); } $dest = realpath($options['destination']); } else { $pwd = getcwd(); if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) { $dest = $pwd . DIRECTORY_SEPARATOR . 'ext'; } else { $dest = $pwd; } } $dest .= DIRECTORY_SEPARATOR . $pkgname; $orig = $pkgname . '-' . $pkginfo['version']; $tar = new Archive_Tar($pkgfile); if (!@$tar->extractModify($dest, $orig)) { return $this->raiseError("unable to unpack {$pkgfile}"); } $this->ui->outputData("Package ready at '{$dest}'"); // }}} }
/** * @param string full URL to REST resource * @param string original contents of the REST resource * @param array HTTP Last-Modified and ETag headers * @param bool if true, then the cache id file should be regenerated to * trigger a new time-to-live value */ function saveCache($url, $contents, $lastmodified, $nochange = false, $cacheid = null) { $cache_dir = $this->config->get('cache_dir'); $d = $cache_dir . DIRECTORY_SEPARATOR . md5($url); $cacheidfile = $d . 'rest.cacheid'; $cachefile = $d . 'rest.cachefile'; if (!is_dir($cache_dir)) { if (System::mkdir(array('-p', $cache_dir)) === false) { return PEAR::raiseError("The value of config option cache_dir ({$cache_dir}) is not a directory and attempts to create the directory failed."); } } if (!is_writeable($cache_dir)) { // If writing to the cache dir is not going to work, silently do nothing. // An ugly hack, but retains compat with PEAR 1.9.1 where many commands // work fine as non-root user (w/out write access to default cache dir). return true; } if ($cacheid === null && $nochange) { $cacheid = unserialize(implode('', file($cacheidfile))); } $idData = serialize(array('age' => time(), 'lastChange' => $nochange ? $cacheid['lastChange'] : $lastmodified)); $result = $this->saveCacheFile($cacheidfile, $idData); if (PEAR::isError($result)) { return $result; } elseif ($nochange) { return true; } $result = $this->saveCacheFile($cachefile, serialize($contents)); if (PEAR::isError($result)) { if (file_exists($cacheidfile)) { @unlink($cacheidfile); } return $result; } return true; }
/** * @param string full URL to REST resource * @param string original contents of the REST resource * @param array HTTP Last-Modified and ETag headers * @param bool if true, then the cache id file should be regenerated to * trigger a new time-to-live value */ function saveCache($url, $contents, $lastmodified, $nochange = false, $cacheid = null) { $cacheidfile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR . md5($url) . 'rest.cacheid'; $cachefile = $this->config->get('cache_dir') . DIRECTORY_SEPARATOR . md5($url) . 'rest.cachefile'; if ($cacheid === null && $nochange) { $cacheid = unserialize(implode('', file($cacheidfile))); } $fp = @fopen($cacheidfile, 'wb'); if (!$fp) { $cache_dir = $this->config->get('cache_dir'); if (!is_dir($cache_dir)) { System::mkdir(array('-p', $cache_dir)); $fp = @fopen($cacheidfile, 'wb'); if (!$fp) { return false; } } else { return false; } } if ($nochange) { fwrite($fp, serialize(array('age' => time(), 'lastChange' => $cacheid['lastChange']))); fclose($fp); return true; } else { fwrite($fp, serialize(array('age' => time(), 'lastChange' => $lastmodified))); } fclose($fp); $fp = @fopen($cachefile, 'wb'); if (!$fp) { @unlink($cacheidfile); return false; } fwrite($fp, serialize($contents)); fclose($fp); return true; }
function generateClasses() { //echo "Generating Class files: \n"; $options =& PEAR::getStaticProperty('DB_DataObject', 'options'); $base = $options['class_location']; if (!file_exists($base)) { require_once 'System.php'; System::mkdir(array('-p', $base)); } $class_prefix = $options['class_prefix']; if ($extends = @$options['extends']) { $this->_extends = $extends; $this->_extendsFile = $options['extends_location']; } foreach ($this->tables as $this->table) { $this->table = trim($this->table); $this->classname = $class_prefix . preg_replace('/[^A-Z0-9]/i', '_', ucfirst($this->table)); $i = ''; $outfilename = "{$base}/" . preg_replace('/[^A-Z0-9]/i', '_', ucfirst($this->table)) . ".php"; if (file_exists($outfilename)) { $i = implode('', file($outfilename)); } $out = $this->_generateClassTable($i); $this->debug("writing {$this->classname}\n"); $fh = fopen($outfilename, "w"); fputs($fh, $out); fclose($fh); } //echo $out; }
/** * Make sure the directory where we keep registry files for channels exists * * @return bool TRUE if directory exists, FALSE if it could not be * created * * @access private */ function _assertChannelDir() { if (!@is_dir($this->channelsdir)) { if (!$this->hasWriteAccess()) { return false; } require_once 'System.php'; if (!System::mkdir(array('-p', $this->channelsdir))) { return $this->raiseError("could not create directory '{$this->channelsdir}'"); } } if (!@is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) { if (!$this->hasWriteAccess()) { return false; } require_once 'System.php'; if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR . '.alias'))) { return $this->raiseError("could not create directory '{$this->channelsdir}/.alias'"); } } return true; }
/** * Gets the filename that will be used to save these files * * @param array $files The files to be compiled * @param string $path The path to save the compiled file to * @param string $type The mime type css or js to save the compiled file to * * @return string */ private static function get_filename($files, $path, $type) { // Most recently modified file $last_modified = 0; foreach ($files as $file) { $raw_file = self::_get_file_path($file, $type); // Check if this file was the most recently modified $last_modified = max(filemtime($raw_file), $last_modified); } if (Theme::$is_admin == TRUE) { $path = $path . DS . 'admin'; } //set unqiue filename based on criteria $filename = $path . DS . $type . DS . $type . '-' . md5(implode("|", $files)) . $last_modified . '.' . $type; $directory = dirname($filename); if (!is_dir($directory)) { // Recursively create the directories needed for the file System::mkdir($directory, 0777, TRUE); } return $filename; }
/** * Convert a table name into a file name -> override this if you want a different mapping * * @access public * @return string file name; */ function getFileNameFromTableName($table) { $options =& PEAR::getStaticProperty('DB_DataObject', 'options'); $base = $options['class_location']; if (strpos($base, '%s') !== false) { $base = dirname($base); } if (!file_exists($base)) { require_once 'System.php'; System::mkdir(array('-p', $base)); } if (strpos($options['class_location'], '%s') !== false) { $outfilename = sprintf($options['class_location'], preg_replace('/[^A-Z0-9]/i', '_', ucfirst($this->table))); } else { $outfilename = "{$base}/" . preg_replace('/[^A-Z0-9]/i', '_', ucfirst($this->table)) . ".php"; } return $outfilename; }
$rest_path = '/var/lib/pearweb/rest'; } else { $rest_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'public_html' . DIRECTORY_SEPARATOR . 'rest'; } include_once 'DB.php'; if (empty($dbh)) { $options = array('persistent' => false, 'portability' => DB_PORTABILITY_ALL); $dbh =& DB::connect(PEAR_DATABASE_DSN, $options); } $pear_rest = new pearweb_Channel_REST_Generator($rest_path, $dbh); } ob_end_clean(); PEAR::setErrorHandling(PEAR_ERROR_DIE); require_once 'System.php'; System::rm(array('-r', $rest_path)); System::mkdir(array('-p', $rest_path)); chmod($rest_path, 0777); echo "Generating Category REST...\n"; include_once 'pear-database-category.php'; foreach (category::listAll() as $category) { echo " {$category['name']}..."; $pear_rest->saveCategoryREST($category['name']); echo "done\n"; } $pear_rest->saveAllCategoriesREST(); echo "Generating Maintainer REST...\n"; $maintainers = $dbh->getAll('SELECT users.* FROM users, karma WHERE users.handle = karma.user AND (karma.level = "pear.dev" OR karma.level = "pear.admin")', array(), DB_FETCHMODE_ASSOC); foreach ($maintainers as $maintainer) { echo " {$maintainer['handle']}..."; $pear_rest->saveMaintainerREST($maintainer['handle']);
function generateClasses() { //echo "Generating Class files: \n"; $options =& PEAR::getStaticProperty('DB_DataObject', 'options'); $base = $options['class_location']; if (strpos($base, '%s') !== false) { $base = dirname($base); } if (!file_exists($base)) { require_once 'System.php'; System::mkdir(array('-p', $base)); } $class_prefix = $options['class_prefix']; if ($extends = @$options['extends']) { $this->_extends = $extends; $this->_extendsFile = $options['extends_location']; } foreach ($this->tables as $this->table) { $this->table = trim($this->table); $this->classname = $class_prefix . preg_replace('/[^A-Z0-9]/i', '_', $this->CamelCaseFromUnderscore($this->table)); $i = ''; if (strpos($options['class_location'], '%s') !== false) { $outfilename = sprintf($options['class_location'], preg_replace('/[^A-Z0-9]/i', '_', $this->CamelCaseFromUnderscore($this->table))); } else { $outfilename = "{$base}/" . preg_replace('/[^A-Z0-9]/i', '_', $this->CamelCaseFromUnderscore($this->table)) . ".php"; } $oldcontents = ''; if (file_exists($outfilename)) { // file_get_contents??? $oldcontents = implode('', file($outfilename)); } $out = $this->_generateClassTable($oldcontents); $this->debug("writing {$this->classname}\n"); $fh = fopen($outfilename, "w"); fputs($fh, $out); fclose($fh); } //echo $out; }
/** * @param string full URL to REST resource * @param string original contents of the REST resource * @param array HTTP Last-Modified and ETag headers * @param bool if true, then the cache id file should be regenerated to * trigger a new time-to-live value */ function saveCache($url, $contents, $lastmodified, $nochange = false, $cacheid = null) { $cache_dir = $this->config->get('cache_dir'); $d = $cache_dir . DIRECTORY_SEPARATOR . md5($url); $cacheidfile = $d . 'rest.cacheid'; $cachefile = $d . 'rest.cachefile'; if ($cacheid === null && $nochange) { $cacheid = unserialize(implode('', file($cacheidfile))); } if (is_link($cacheidfile)) { return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $cacheidfile . ' as it is symlinked to ' . readlink($cacheidfile) . ' - Possible symlink attack'); } if (is_link($cachefile)) { return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $cacheidfile . ' as it is symlinked to ' . readlink($cacheidfile) . ' - Possible symlink attack'); } $cacheidfile_fp = @fopen($cacheidfile, 'wb'); if (!$cacheidfile_fp) { if (is_dir($cache_dir)) { return PEAR::raiseError("The value of config option cache_dir ({$cache_dir}) is not a directory. "); } System::mkdir(array('-p', $cache_dir)); $cacheidfile_fp = @fopen($cacheidfile, 'wb'); if (!$cacheidfile_fp) { return PEAR::raiseError("Could not open {$cacheidfile} for writing."); } } if ($nochange) { fwrite($cacheidfile_fp, serialize(array('age' => time(), 'lastChange' => $cacheid['lastChange']))); fclose($cacheidfile_fp); return true; } fwrite($cacheidfile_fp, serialize(array('age' => time(), 'lastChange' => $lastmodified))); fclose($cacheidfile_fp); $cachefile_fp = @fopen($cachefile, 'wb'); if (!$cachefile_fp) { if (file_exists($cacheidfile)) { @unlink($cacheidfile); } return PEAR::raiseError("Could not open {$cacheidfile} for writing."); } fwrite($cachefile_fp, serialize($contents)); fclose($cachefile_fp); return true; }
/** * Installs the files within the package file specified. * * @param string $pkgfile path to the package file * @param array $options * recognized options: * - installroot : optional prefix directory for installation * - force : force installation * - register-only : update registry but don't install files * - upgrade : upgrade existing install * - soft : fail silently * - nodeps : ignore dependency conflicts/missing dependencies * - alldeps : install all dependencies * - onlyreqdeps : install only required dependencies * * @return array|PEAR_Error package info if successful */ function install($pkgfile, $options = array()) { $php_dir = $this->config->get('php_dir'); if (isset($options['installroot'])) { if (substr($options['installroot'], -1) == DIRECTORY_SEPARATOR) { $options['installroot'] = substr($options['installroot'], 0, -1); } $php_dir = $this->_prependPath($php_dir, $options['installroot']); $this->installroot = $options['installroot']; } else { $this->installroot = ''; } $this->registry =& new PEAR_Registry($php_dir); // ==> XXX should be removed later on $flag_old_format = false; if (substr($pkgfile, -4) == '.xml') { $descfile = $pkgfile; } else { // {{{ Decompress pack in tmp dir ------------------------------------- // To allow relative package file names $pkgfile = realpath($pkgfile); if (PEAR::isError($tmpdir = System::mktemp('-d'))) { return $tmpdir; } $this->log(3, '+ tmp dir created at ' . $tmpdir); $tar = new Archive_Tar($pkgfile); if (!@$tar->extract($tmpdir)) { return $this->raiseError("unable to unpack {$pkgfile}"); } // {{{ Look for existing package file $descfile = $tmpdir . DIRECTORY_SEPARATOR . 'package.xml'; if (!is_file($descfile)) { // ----- Look for old package archive format // In this format the package.xml file was inside the // Package-n.n directory $dp = opendir($tmpdir); do { $pkgdir = readdir($dp); } while ($pkgdir[0] == '.'); $descfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml'; $flag_old_format = true; $this->log(0, "warning : you are using an archive with an old format"); } // }}} // <== XXX This part should be removed later on // }}} } if (!is_file($descfile)) { return $this->raiseError("no package.xml file after extracting the archive"); } // Parse xml file ----------------------------------------------- $pkginfo = $this->infoFromDescriptionFile($descfile); if (PEAR::isError($pkginfo)) { return $pkginfo; } $this->validatePackageInfo($pkginfo, $errors, $warnings); // XXX We allow warnings, do we have to do it? if (count($errors)) { if (empty($options['force'])) { return $this->raiseError("The following errors where found (use force option to install anyway):\n" . implode("\n", $errors)); } else { $this->log(0, "warning : the following errors were found:\n" . implode("\n", $errors)); } } $pkgname = $pkginfo['package']; // {{{ Check dependencies ------------------------------------------- if (isset($pkginfo['release_deps']) && empty($options['nodeps'])) { $dep_errors = ''; $error = $this->checkDeps($pkginfo, $dep_errors); if ($error == true) { if (empty($options['soft'])) { $this->log(0, substr($dep_errors, 1)); } return $this->raiseError("{$pkgname}: Dependencies failed"); } else { if (!empty($dep_errors)) { // Print optional dependencies if (empty($options['soft'])) { $this->log(0, $dep_errors); } } } } // }}} // {{{ checks to do when not in "force" mode if (empty($options['force'])) { $test = $this->registry->checkFileMap($pkginfo); if (sizeof($test)) { $tmp = $test; foreach ($tmp as $file => $pkg) { if ($pkg == $pkgname) { unset($test[$file]); } } if (sizeof($test)) { $msg = "{$pkgname}: conflicting files found:\n"; $longest = max(array_map("strlen", array_keys($test))); $fmt = "%{$longest}s (%s)\n"; foreach ($test as $file => $pkg) { $msg .= sprintf($fmt, $file, $pkg); } return $this->raiseError($msg); } } } // }}} $this->startFileTransaction(); if (empty($options['upgrade'])) { // checks to do only when installing new packages if (empty($options['force']) && $this->registry->packageExists($pkgname)) { return $this->raiseError("{$pkgname} already installed"); } } else { if ($this->registry->packageExists($pkgname)) { $v1 = $this->registry->packageInfo($pkgname, 'version'); $v2 = $pkginfo['version']; $cmp = version_compare("{$v1}", "{$v2}", 'gt'); if (empty($options['force']) && !version_compare("{$v2}", "{$v1}", 'gt')) { return $this->raiseError("upgrade to a newer version ({$v2} is not newer than {$v1})"); } if (empty($options['register-only'])) { // when upgrading, remove old release's files first: if (PEAR::isError($err = $this->_deletePackageFiles($pkgname))) { return $this->raiseError($err); } } } } // {{{ Copy files to dest dir --------------------------------------- // info from the package it self we want to access from _installFile $this->pkginfo =& $pkginfo; // used to determine whether we should build any C code $this->source_files = 0; if (empty($options['register-only'])) { if (!is_dir($php_dir)) { return $this->raiseError("no script destination directory\n", null, PEAR_ERROR_DIE); } $tmp_path = dirname($descfile); if (substr($pkgfile, -4) != '.xml') { $tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkginfo['version']; } // ==> XXX This part should be removed later on if ($flag_old_format) { $tmp_path = dirname($descfile); } // <== XXX This part should be removed later on // {{{ install files foreach ($pkginfo['filelist'] as $file => $atts) { $this->expectError(PEAR_INSTALLER_FAILED); $res = $this->_installFile($file, $atts, $tmp_path, $options); $this->popExpect(); if (PEAR::isError($res)) { if (empty($options['ignore-errors'])) { $this->rollbackFileTransaction(); if ($res->getMessage() == "file does not exist") { $this->raiseError("file {$file} in package.xml does not exist"); } return $this->raiseError($res); } else { $this->log(0, "Warning: " . $res->getMessage()); } } if ($res != PEAR_INSTALLER_OK) { // Do not register files that were not installed unset($pkginfo['filelist'][$file]); } } // }}} // {{{ compile and install source files if ($this->source_files > 0 && empty($options['nobuild'])) { $this->log(1, "{$this->source_files} source files, building"); $bob =& new PEAR_Builder($this->ui); $bob->debug = $this->debug; $built = $bob->build($descfile, array(&$this, '_buildCallback')); if (PEAR::isError($built)) { $this->rollbackFileTransaction(); return $built; } $this->log(1, "\nBuild process completed successfully"); foreach ($built as $ext) { $bn = basename($ext['file']); list($_ext_name, ) = explode('.', $bn); if (extension_loaded($_ext_name)) { $this->raiseError("Extension '{$_ext_name}' already loaded. Please unload it " . "in your php.ini file prior to install or upgrade it."); } // extension dir must be created if it doesn't exist // patch by Tomas Cox (modified by Greg Beaver) $ext_dir = $this->config->get('ext_dir'); if (!@is_dir($ext_dir) && !System::mkdir(array('-p', $ext_dir))) { $this->log(3, "+ mkdir -p {$ext_dir}"); return $this->raiseError("failed to create extension dir '{$ext_dir}'"); } $dest = $ext_dir . DIRECTORY_SEPARATOR . $bn; $this->log(1, "Installing '{$bn}' at ext_dir ({$dest})"); $this->log(3, "+ cp {$ext['file']} ext_dir ({$dest})"); $copyto = $this->_prependPath($dest, $this->installroot); if (!@copy($ext['file'], $copyto)) { $this->rollbackFileTransaction(); return $this->raiseError("failed to copy {$bn} to {$copyto}"); } $pkginfo['filelist'][$bn] = array('role' => 'ext', 'installed_as' => $dest, 'php_api' => $ext['php_api'], 'zend_mod_api' => $ext['zend_mod_api'], 'zend_ext_api' => $ext['zend_ext_api']); } } // }}} } if (!$this->commitFileTransaction()) { $this->rollbackFileTransaction(); return $this->raiseError("commit failed", PEAR_INSTALLER_FAILED); } // }}} $ret = false; // {{{ Register that the package is installed ----------------------- if (empty($options['upgrade'])) { // if 'force' is used, replace the info in registry if (!empty($options['force']) && $this->registry->packageExists($pkgname)) { $this->registry->deletePackage($pkgname); } $ret = $this->registry->addPackage($pkgname, $pkginfo); } else { // new: upgrade installs a package if it isn't installed if (!$this->registry->packageExists($pkgname)) { $ret = $this->registry->addPackage($pkgname, $pkginfo); } else { $ret = $this->registry->updatePackage($pkgname, $pkginfo, false); } } if (!$ret) { return $this->raiseError("Adding package {$pkgname} to registry failed"); } // }}} return $pkginfo; }
/** * @param string full URL to REST resource * @param string original contents of the REST resource * @param array HTTP Last-Modified and ETag headers * @param bool if true, then the cache id file should be regenerated to * trigger a new time-to-live value */ function saveCache($url, $contents, $lastmodified, $nochange = false, $cacheid = null) { $cache_dir = $this->config->get('cache_dir'); $d = $cache_dir . DIRECTORY_SEPARATOR . md5($url); $cacheidfile = $d . 'rest.cacheid'; $cachefile = $d . 'rest.cachefile'; if (!is_dir($cache_dir)) { if (System::mkdir(array('-p', $cache_dir)) === false) { return PEAR::raiseError("The value of config option cache_dir ({$cache_dir}) is not a directory and attempts to create the directory failed."); } } if ($cacheid === null && $nochange) { $cacheid = unserialize(implode('', file($cacheidfile))); } $idData = serialize(array('age' => time(), 'lastChange' => $nochange ? $cacheid['lastChange'] : $lastmodified)); $result = $this->saveCacheFile($cacheidfile, $idData); if (PEAR::isError($result)) { return $result; } elseif ($nochange) { return true; } $result = $this->saveCacheFile($cachefile, serialize($contents)); if (PEAR::isError($result)) { if (file_exists($cacheidfile)) { @unlink($cacheidfile); } return $result; } return true; }
/** * Installs the files within the package file specified. * * @param string|PEAR_Downloader_Package $pkgfile path to the package file, * or a pre-initialized packagefile object * @param array $options * recognized options: * - installroot : optional prefix directory for installation * - force : force installation * - register-only : update registry but don't install files * - upgrade : upgrade existing install * - soft : fail silently * - nodeps : ignore dependency conflicts/missing dependencies * - alldeps : install all dependencies * - onlyreqdeps : install only required dependencies * * @return array|PEAR_Error package info if successful */ function install($pkgfile, $options = array()) { $this->_options = $options; $this->_registry =& $this->config->getRegistry(); if (is_object($pkgfile)) { $dlpkg =& $pkgfile; $pkg = $pkgfile->getPackageFile(); $pkgfile = $pkg->getArchiveFile(); $descfile = $pkg->getPackageFile(); $tmpdir = dirname($descfile); } else { $descfile = $pkgfile; $tmpdir = ''; if (PEAR::isError($pkg =& $this->_parsePackageXml($descfile, $tmpdir))) { return $pkg; } } if (realpath($descfile) != realpath($pkgfile)) { $tar = new Archive_Tar($pkgfile); if (!@$tar->extract($tmpdir)) { return $this->raiseError("unable to unpack {$pkgfile}"); } } $pkgname = $pkg->getName(); $channel = $pkg->getChannel(); if (isset($this->_options['packagingroot'])) { $packrootphp_dir = $this->_prependPath($this->config->get('php_dir', null, $channel), $this->_options['packagingroot']); } if (isset($options['installroot'])) { $this->config->setInstallRoot($options['installroot']); $this->_registry =& $this->config->getRegistry(); $installregistry =& $this->_registry; $this->installroot = ''; // all done automagically now $php_dir = $this->config->get('php_dir', null, $channel); } else { $this->config->setInstallRoot(false); $this->_registry =& $this->config->getRegistry(); if (isset($this->_options['packagingroot'])) { $installregistry =& new PEAR_Registry($packrootphp_dir); $php_dir = $packrootphp_dir; } else { $installregistry =& $this->_registry; $php_dir = $this->config->get('php_dir', null, $channel); } $this->installroot = ''; } // {{{ checks to do when not in "force" mode if (empty($options['force']) && @is_dir($this->config->get('php_dir'))) { $testp = $channel == 'pear.php.net' ? $pkgname : array($channel, $pkgname); $instfilelist = $pkg->getInstallationFileList(true); if (PEAR::isError($instfilelist)) { return $instfilelist; } $test = $installregistry->checkFileMap($instfilelist, $testp, '1.1'); if (PEAR::isError($test)) { return $test; } if (sizeof($test)) { $pkgs = $this->getInstallPackages(); $found = false; foreach ($pkgs as $param) { if ($pkg->isSubpackageOf($param)) { $found = true; break; } } if ($found) { // subpackages can conflict with earlier versions of parent packages $parentreg = $installregistry->packageInfo($param->getPackage(), null, $param->getChannel()); $tmp = $test; foreach ($tmp as $file => $info) { if (is_array($info)) { if (strtolower($info[1]) == strtolower($param->getPackage()) && strtolower($info[0]) == strtolower($param->getChannel())) { unset($test[$file]); unset($parentreg['filelist'][$file]); } } else { if (strtolower($param->getChannel()) != 'pear.php.net') { continue; } if (strtolower($info) == strtolower($param->getPackage())) { unset($test[$file]); unset($parentreg['filelist'][$file]); } } } $pfk =& new PEAR_PackageFile($this->config); $parentpkg =& $pfk->fromArray($parentreg); $installregistry->updatePackage2($parentpkg); } if ($param->getChannel() == 'pecl.php.net' && isset($options['upgrade'])) { $tmp = $test; foreach ($tmp as $file => $info) { if (is_string($info)) { // pear.php.net packages are always stored as strings if (strtolower($info) == strtolower($param->getPackage())) { // upgrading existing package unset($test[$file]); } } } } if (sizeof($test)) { $msg = "{$channel}/{$pkgname}: conflicting files found:\n"; $longest = max(array_map("strlen", array_keys($test))); $fmt = "%{$longest}s (%s)\n"; foreach ($test as $file => $info) { if (!is_array($info)) { $info = array('pear.php.net', $info); } $info = $info[0] . '/' . $info[1]; $msg .= sprintf($fmt, $file, $info); } if (!isset($options['ignore-errors'])) { return $this->raiseError($msg); } else { if (!isset($options['soft'])) { $this->log(0, "WARNING: {$msg}"); } } } } } // }}} $this->startFileTransaction(); if (empty($options['upgrade']) && empty($options['soft'])) { // checks to do only when installing new packages if ($channel == 'pecl.php.net') { $test = $installregistry->packageExists($pkgname, $channel); if (!$test) { $test = $installregistry->packageExists($pkgname, 'pear.php.net'); } } else { $test = $installregistry->packageExists($pkgname, $channel); } if (empty($options['force']) && $test) { return $this->raiseError("{$channel}/{$pkgname} is already installed"); } } else { $usechannel = $channel; if ($channel == 'pecl.php.net') { $test = $installregistry->packageExists($pkgname, $channel); if (!$test) { $test = $installregistry->packageExists($pkgname, 'pear.php.net'); $usechannel = 'pear.php.net'; } } else { $test = $installregistry->packageExists($pkgname, $channel); } if ($test) { $v1 = $installregistry->packageInfo($pkgname, 'version', $usechannel); $v2 = $pkg->getVersion(); $cmp = version_compare("{$v1}", "{$v2}", 'gt'); if (empty($options['force']) && !version_compare("{$v2}", "{$v1}", 'gt')) { return $this->raiseError("upgrade to a newer version ({$v2} is not newer than {$v1})"); } if (empty($options['register-only'])) { // when upgrading, remove old release's files first: if (PEAR::isError($err = $this->_deletePackageFiles($pkgname, $usechannel, true))) { if (!isset($options['ignore-errors'])) { return $this->raiseError($err); } else { if (!isset($options['soft'])) { $this->log(0, 'WARNING: ' . $err->getMessage()); } } } else { $backedup = $err; } } } } // {{{ Copy files to dest dir --------------------------------------- // info from the package it self we want to access from _installFile $this->pkginfo =& $pkg; // used to determine whether we should build any C code $this->source_files = 0; $savechannel = $this->config->get('default_channel'); if (empty($options['register-only']) && !is_dir($php_dir)) { if (PEAR::isError(System::mkdir(array('-p'), $php_dir))) { return $this->raiseError("no installation destination directory '{$php_dir}'\n"); } } $tmp_path = dirname($descfile); if (substr($pkgfile, -4) != '.xml') { $tmp_path .= DIRECTORY_SEPARATOR . $pkgname . '-' . $pkg->getVersion(); } $this->configSet('default_channel', $channel); // {{{ install files if ($pkg->getPackagexmlVersion() == '2.0') { $filelist = $pkg->getInstallationFilelist(); } else { $filelist = $pkg->getFileList(); } if (PEAR::isError($filelist)) { return $filelist; } $pkg->resetFilelist(); $pkg->setLastInstalledVersion($installregistry->packageInfo($pkg->getPackage(), 'version', $pkg->getChannel())); foreach ($filelist as $file => $atts) { if ($pkg->getPackagexmlVersion() == '1.0') { $this->expectError(PEAR_INSTALLER_FAILED); $res = $this->_installFile($file, $atts, $tmp_path, $options); $this->popExpect(); } else { $this->expectError(PEAR_INSTALLER_FAILED); $res = $this->_installFile2($pkg, $file, $atts, $tmp_path, $options); $this->popExpect(); } if (PEAR::isError($res)) { if (empty($options['ignore-errors'])) { $this->rollbackFileTransaction(); if ($res->getMessage() == "file does not exist") { $this->raiseError("file {$file} in package.xml does not exist"); } return $this->raiseError($res); } else { if (!isset($options['soft'])) { $this->log(0, "Warning: " . $res->getMessage()); } } } if ($res == PEAR_INSTALLER_OK) { // Register files that were installed $pkg->installedFile($file, $atts); } } // }}} // {{{ compile and install source files if ($this->source_files > 0 && empty($options['nobuild'])) { if (PEAR::isError($err = $this->_compileSourceFiles($savechannel, $pkg))) { return $err; } } // }}} if (isset($backedup)) { $this->_removeBackups($backedup); } if (!$this->commitFileTransaction()) { $this->rollbackFileTransaction(); $this->configSet('default_channel', $savechannel); return $this->raiseError("commit failed", PEAR_INSTALLER_FAILED); } // }}} $ret = false; $installphase = 'install'; $oldversion = false; // {{{ Register that the package is installed ----------------------- if (empty($options['upgrade'])) { // if 'force' is used, replace the info in registry $usechannel = $channel; if ($channel == 'pecl.php.net') { $test = $installregistry->packageExists($pkgname, $channel); if (!$test) { $test = $installregistry->packageExists($pkgname, 'pear.php.net'); $usechannel = 'pear.php.net'; } } else { $test = $installregistry->packageExists($pkgname, $channel); } if (!empty($options['force']) && $test) { $oldversion = $installregistry->packageInfo($pkgname, 'version', $usechannel); $installregistry->deletePackage($pkgname, $usechannel); } $ret = $installregistry->addPackage2($pkg); } else { $usechannel = $channel; if ($channel == 'pecl.php.net') { $test = $installregistry->packageExists($pkgname, $channel); if (!$test) { $test = $installregistry->packageExists($pkgname, 'pear.php.net'); $usechannel = 'pear.php.net'; } } else { $test = $installregistry->packageExists($pkgname, $channel); } // new: upgrade installs a package if it isn't installed if (!$test) { $ret = $installregistry->addPackage2($pkg); } else { if ($usechannel != $channel) { $installregistry->deletePackage($pkgname, $usechannel); $ret = $installregistry->addPackage2($pkg); } else { $ret = $installregistry->updatePackage2($pkg); } $installphase = 'upgrade'; } } if (!$ret) { $this->configSet('default_channel', $savechannel); return $this->raiseError("Adding package {$channel}/{$pkgname} to registry failed"); } // }}} $this->configSet('default_channel', $savechannel); if (class_exists('PEAR_Task_Common')) { // this is auto-included if any tasks exist if (PEAR_Task_Common::hasPostinstallTasks()) { PEAR_Task_Common::runPostinstallTasks($installphase); } } return $pkg->toArray(true); }
function saveAllMaintainersREST() { $maintainers = user::listAll(); $info = '<?xml version="1.0" encoding="UTF-8" ?> <m xmlns="http://pear.php.net/dtd/rest.allmaintainers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://pear.php.net/dtd/rest.allmaintainers http://pear.php.net/dtd/rest.allmaintainers.xsd">' . "\n"; // package information require_once 'Damblan/Karma.php'; $karma =& new Damblan_Karma($GLOBALS['dbh']); foreach ($maintainers as $maintainer) { if (!$karma->has($maintainer['handle'], 'pear.dev')) { continue; } $info .= ' <h xlink:href="/rest/m/' . $maintainer['handle'] . '">' . $maintainer['handle'] . '</h>' . "\n"; } $info .= '</m>'; $mdir = $this->_restdir . DIRECTORY_SEPARATOR . 'm'; if (!is_dir($mdir)) { System::mkdir(array('-p', $mdir)); @chmod($mdir, 0777); } file_put_contents($mdir . DIRECTORY_SEPARATOR . 'allmaintainers.xml', $info); @chmod($mdir . DIRECTORY_SEPARATOR . 'allmaintainers.xml', 0666); }
public function action_systemcheck() { $this->template->title = __('System Check'); $this->template->_activity = __('40'); $this->template->menu = array(HTML::anchor(Route::get('install')->uri(), __('Welcome')), HTML::anchor(Route::get('install')->uri(array('action' => 'systemcheck')), __('System Check')), __('Database'), __('Install'), __('Finish')); !file_exists(APPPATH . "cache") && System::mkdir(APPPATH . "cache"); !file_exists(APPPATH . "config") && System::mkdir(APPPATH . "config"); !file_exists(APPPATH . "logs") && System::mkdir(APPPATH . "logs"); !file_exists(APPPATH . "uploads") && System::mkdir(APPPATH . "uploads"); !file_exists(APPPATH . "media") && System::mkdir(APPPATH . "media"); !file_exists(APPPATH . "media/pictures") && System::mkdir(APPPATH . "media/pictures"); !file_exists(DOCROOT . "media") && System::mkdir(DOCROOT . "media"); !file_exists(DOCROOT . "media/css") && System::mkdir(DOCROOT . "media/css"); !file_exists(DOCROOT . "media/js") && System::mkdir(DOCROOT . "media/js"); $view = View::factory('install/systemcheck', System::check()); if ($view->php_version and $view->mysqli and $view->system_directory and $view->application_directory and $view->modules_directory and $view->config_writable and $view->cache_writable and $view->pcre_utf8 and $view->pcre_unicode and $view->reflection_enabled and $view->filters_enabled and $view->iconv_loaded and $view->spl_autoload_register and $view->simplexml and $view->json_encode and $view->mbstring and $view->ctype_digit and $view->uri_determination and $view->gd_info) { $this->request->redirect(Route::get('install')->uri(array('action' => 'database'))); } else { $this->template->error = __('Gleez may not work correctly with your environment.'); } $this->template->content = $view; }
/** * Make sure the directory where we keep registry files for channels exists * * @return bool TRUE if directory exists, FALSE if it could not be * created * * @access private */ function _assertChannelDir() { if (!file_exists($this->channelsdir)) { if (!$this->hasWriteAccess()) { return false; } require_once 'System.php'; if (!System::mkdir(array('-p', $this->channelsdir))) { return $this->raiseError("could not create directory '{$this->channelsdir}'"); } } elseif (!is_dir($this->channelsdir)) { return $this->raiseError("could not create directory '{$this->channelsdir}" . "', it already exists and is not a directory"); } if (!file_exists($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) { if (!$this->hasWriteAccess()) { return false; } require_once 'System.php'; if (!System::mkdir(array('-p', $this->channelsdir . DIRECTORY_SEPARATOR . '.alias'))) { return $this->raiseError("could not create directory '{$this->channelsdir}/.alias'"); } } elseif (!is_dir($this->channelsdir . DIRECTORY_SEPARATOR . '.alias')) { return $this->raiseError("could not create directory '{$this->channelsdir}" . "/.alias', it already exists and is not a directory"); } return true; }
function writeFile($f, $str) { require_once 'System.php'; System::mkdir(array('-p', dirname($f))); // overwrite??? echo "write: {$f}\n"; file_put_contents($f, $str); }
function doBundle($command, $options, $params) { $downloader =& $this->getDownloader($this->ui, array('force' => true, 'nodeps' => true, 'soft' => true, 'downloadonly' => true), $this->config); $reg =& $this->config->getRegistry(); if (sizeof($params) < 1) { return $this->raiseError("Please supply the package you want to bundle"); } if (isset($options['destination'])) { if (!is_dir($options['destination'])) { System::mkdir('-p ' . $options['destination']); } $dest = realpath($options['destination']); } else { $pwd = getcwd(); if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) { $dest = $pwd . DIRECTORY_SEPARATOR . 'ext'; } else { $dest = $pwd; } } PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $err = $downloader->setDownloadDir($dest); PEAR::staticPopErrorHandling(); if (PEAR::isError($err)) { return PEAR::raiseError('download directory "' . $dest . '" is not writeable.'); } $result =& $downloader->download(array($params[0])); if (PEAR::isError($result)) { return $result; } if (!isset($result[0])) { return $this->raiseError('unable to unpack ' . $params[0]); } $pkgfile =& $result[0]->getPackageFile(); $pkgname = $pkgfile->getName(); $pkgversion = $pkgfile->getVersion(); // Unpacking ------------------------------------------------- $dest .= DIRECTORY_SEPARATOR . $pkgname; $orig = $pkgname . '-' . $pkgversion; $tar =& new Archive_Tar($pkgfile->getArchiveFile()); if (!$tar->extractModify($dest, $orig)) { return $this->raiseError('unable to unpack ' . $pkgfile->getArchiveFile()); } $this->ui->outputData("Package ready at '{$dest}'"); // }}} }
/** * Package up both a package.xml and package2.xml for the same release * @param PEAR_Packager * @param PEAR_PackageFile_v1 * @param bool generate a .tgz or a .tar * @param string|null temporary directory to package in */ function toTgz2(&$packager, &$pf1, $compress = true, $where = null) { require_once 'Archive/Tar.php'; if (!$this->_packagefile->isEquivalent($pf1)) { return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: "' . basename($pf1->getPackageFile()) . '" is not equivalent to "' . basename($this->_packagefile->getPackageFile()) . '"'); } if ($where === null) { if (!($where = System::mktemp(array('-d')))) { return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: mktemp failed'); } } elseif (!@System::mkDir(array('-p', $where))) { return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: "' . $where . '" could' . ' not be created'); } if (file_exists($where . DIRECTORY_SEPARATOR . 'package.xml') && !is_file($where . DIRECTORY_SEPARATOR . 'package.xml')) { return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: unable to save package.xml as' . ' "' . $where . DIRECTORY_SEPARATOR . 'package.xml"'); } if (!$this->_packagefile->validate(PEAR_VALIDATE_PACKAGING)) { return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: invalid package.xml'); } $ext = $compress ? '.tgz' : '.tar'; $pkgver = $this->_packagefile->getPackage() . '-' . $this->_packagefile->getVersion(); $dest_package = getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext; if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext) && !is_file(getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext)) { return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: cannot create tgz file "' . getcwd() . DIRECTORY_SEPARATOR . $pkgver . $ext . '"'); } if ($pkgfile = $this->_packagefile->getPackageFile()) { $pkgdir = dirname(realpath($pkgfile)); $pkgfile = basename($pkgfile); } else { return PEAR::raiseError('PEAR_Packagefile_v2::toTgz: package file object must ' . 'be created from a real file'); } // {{{ Create the package file list $filelist = array(); $i = 0; $this->_packagefile->flattenFilelist(); $contents = $this->_packagefile->getContents(); if (isset($contents['bundledpackage'])) { // bundles of packages $contents = $contents['bundledpackage']; if (!isset($contents[0])) { $contents = array($contents); } $packageDir = $where; foreach ($contents as $i => $package) { $fname = $package; $file = $pkgdir . DIRECTORY_SEPARATOR . $fname; if (!file_exists($file)) { return $packager->raiseError("File does not exist: {$fname}"); } $tfile = $packageDir . DIRECTORY_SEPARATOR . $fname; System::mkdir(array('-p', dirname($tfile))); copy($file, $tfile); $filelist[$i++] = $tfile; $packager->log(2, "Adding package {$fname}"); } } else { // normal packages $contents = $contents['dir']['file']; if (!isset($contents[0])) { $contents = array($contents); } $packageDir = $where; foreach ($contents as $i => $file) { $fname = $file['attribs']['name']; $atts = $file['attribs']; $orig = $file; $file = $pkgdir . DIRECTORY_SEPARATOR . $fname; if (!file_exists($file)) { return $packager->raiseError("File does not exist: {$fname}"); } else { $tfile = $packageDir . DIRECTORY_SEPARATOR . $fname; unset($orig['attribs']); if (count($orig)) { // file with tasks // run any package-time tasks if (function_exists('file_get_contents')) { $contents = file_get_contents($file); } else { $fp = fopen($file, "r"); $contents = @fread($fp, filesize($file)); fclose($fp); } foreach ($orig as $tag => $raw) { $tag = str_replace($this->_packagefile->getTasksNs() . ':', '', $tag); $task = "PEAR_Task_{$tag}"; $task =& new $task($this->_packagefile->_config, $this->_packagefile->_logger, PEAR_TASK_PACKAGE); $task->init($raw, $atts, null); $res = $task->startSession($this->_packagefile, $contents, $tfile); if (!$res) { continue; // skip this task } if (PEAR::isError($res)) { return $res; } $contents = $res; // save changes System::mkdir(array('-p', dirname($tfile))); $wp = fopen($tfile, "wb"); fwrite($wp, $contents); fclose($wp); } } if (!file_exists($tfile)) { System::mkdir(array('-p', dirname($tfile))); copy($file, $tfile); } $filelist[$i++] = $tfile; $this->_packagefile->setFileAttribute($fname, 'md5sum', md5_file($tfile), $i - 1); $packager->log(2, "Adding file {$fname}"); } } } // }}} if ($pf1 !== null) { $name = 'package2.xml'; } else { $name = 'package.xml'; } $packagexml = $this->toPackageFile($where, PEAR_VALIDATE_PACKAGING, $name); if ($packagexml) { $tar =& new Archive_Tar($dest_package, $compress); $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors // ----- Creates with the package.xml file $ok = $tar->createModify(array($packagexml), '', $where); if (PEAR::isError($ok)) { return $packager->raiseError($ok); } elseif (!$ok) { return $packager->raiseError('PEAR_Packagefile_v2::toTgz(): adding ' . $name . ' failed'); } // ----- Add the content of the package if (!$tar->addModify($filelist, $pkgver, $where)) { return $packager->raiseError('PEAR_Packagefile_v2::toTgz(): tarball creation failed'); } // add the package.xml version 1.0 if ($pf1 !== null) { $pfgen =& $pf1->getDefaultGenerator(); $packagexml1 = $pfgen->toPackageFile($where, PEAR_VALIDATE_PACKAGING, 'package.xml', true); if (!$tar->addModify(array($packagexml1), '', $where)) { return $packager->raiseError('PEAR_Packagefile_v2::toTgz(): adding package.xml failed'); } } return $dest_package; } }
/** * Make sure the directory where we keep registry files exists. * * @return bool TRUE if directory exists, FALSE if it could not be * created * * @access private */ function _assertStateDir() { if (!@is_dir($this->statedir)) { if (!System::mkdir("-p {$this->statedir}")) { return $this->raiseError("could not create directory '{$this->statedir}'"); } } return true; }
/** * Check that the directory exists and is writable * * @since 1.0.1 * * @param $directory * * @uses System::mkdir * @uses Debug::path * * @throws Gleez_Exception */ protected function _checkDir($directory) { if (!is_dir($directory)) { try { // Create the yearly directory System::mkdir($directory); } catch (Exception $e) { throw new Gleez_Exception('Could not create log directory :dir', array(':dir' => Debug::path($directory))); } } if (!is_writable($directory)) { throw new Gleez_Exception('Directory :dir must be writable', array(':dir' => Debug::path($directory))); } }
function setDownloadDir($dir) { if (!@is_writable($dir)) { if (PEAR::isError(System::mkdir(array('-p', $dir)))) { return PEAR::raiseError('download directory "' . $dir . '" is not writeable. Change download_dir config variable to ' . 'a writeable dir'); } } $this->_downloadDir = $dir; }
/** * Create the extensions including * * @access public * @param string Directory to create (default is ./$this->name) */ function createExtension($dirpath = false, $force = false) { // default: create dir in current working directory, // dirname is the extensions base name if (!is_string($dirpath) || $dirpath == "") { $dirpath = "./" . $this->name; } // purge and create extension directory if ($dirpath !== ".") { if (!$force && file_exists($dirpath)) { return PEAR::raiseError("'{$dirpath}' already exists, can't create that directory (use '--force' to override)"); } else { if (!@System::mkdir("-p {$dirpath}")) { return PEAR::raiseError("can't create '{$dirpath}'"); } } } // make path absolute to be independant of working directory changes $this->dirpath = realpath($dirpath); echo "Creating '{$this->name}' extension in '{$dirpath}'\n"; // generate complete source code $this->generateSource(); // copy additional source files if (isset($this->packageFiles['copy'])) { foreach ($this->packageFiles['copy'] as $targetpath => $sourcepath) { $targetpath = $this->dirpath . "/" . $targetpath; if (!is_dir(dirname($targetpath))) { mkdir(dirname($targetpath), 0777, true); } copy($sourcepath, $targetpath); } } // generate README file $this->writeReadme(); // generate DocBook XML documantation for PHP manual $manpath = $this->dirpath . "/manual/" . str_replace('_', '-', $this->name); if (!@System::mkdir("-p {$manpath}")) { return PEAR::raiseError("can't create '{$manpath}'", E_USER_ERROR); } $this->generateDocumentation($manpath); }