예제 #1
0
 public static function getPatch(array $patch)
 {
     static $cache = array();
     if (!isset($cache[$patch['url']])) {
         if (!empty($patch['local'])) {
             if (is_file($patch['url']) && filesize($patch['url'])) {
                 $cache[$patch['url']] = $patch['url'];
             } else {
                 throw new Exception("Unable to read patch from local path {$patch['url']}.");
             }
         } elseif (drush_get_option('no-cache')) {
             $temp_file = drush_tempnam('drush_patchfile_', NULL, '.patch');
             $cache[$patch['url']] = static::downloadPatch($patch['url'], $temp_file);
         } else {
             $cache_file = drush_directory_cache('patchfile') . '/' . md5($patch['url']) . '.patch';
             if (is_file($cache_file) && filectime($cache_file) > $_SERVER['REQUEST_TIME'] - DRUSH_CACHE_LIFETIME_DEFAULT) {
                 drush_log(dt('Remote patch URL @url fetched from cache file @cache.', array('@url' => $patch['url'], '@cache' => $cache_file)));
                 $cache[$patch['url']] = $cache_file;
             } else {
                 $cache[$patch['url']] = static::downloadPatch($patch['url'], $cache_file);
             }
         }
     }
     return $cache[$patch['url']];
 }
예제 #2
0
파일: Project.php 프로젝트: hanoii/drush
 /**
  * Prints release notes for given projects.
  *
  * @param string $version
  *   Version of the release to get notes.
  * @param bool $print_status
  *   Whether to print a informative note.
  * @param string $tmpfile
  *   If provided, a file that contains contents to show before the
  *   release notes.
  */
 function getReleaseNotes($version = NULL, $print_status = TRUE, $tmpfile = NULL)
 {
     $project_name = $this->parsed['short_name'];
     if (!isset($tmpfile)) {
         $tmpfile = drush_tempnam('rln-' . $project_name . '.');
     }
     // Select versions to show.
     $versions = array();
     if (!is_null($version)) {
         $versions[] = $version;
     } else {
         // If requested project is installed,
         // show release notes for the installed version and all newer versions.
         if (isset($this->parsed['recommended'], $this->parsed['installed'])) {
             $releases = array_reverse($this->parsed['releases']);
             foreach ($releases as $version => $release) {
                 if ($release['date'] >= $this->parsed['releases'][$this->parsed['installed']]['date']) {
                     $release += array('version_extra' => '');
                     $this->parsed['releases'][$this->parsed['installed']] += array('version_extra' => '');
                     if ($release['version_extra'] == 'dev' && $this->parsed['releases'][$this->parsed['installed']]['version_extra'] != 'dev') {
                         continue;
                     }
                     $versions[] = $version;
                 }
             }
         } else {
             // Project is not installed and user did not specify a version,
             // so show the release notes for the recommended version.
             $versions[] = $this->parsed['recommended'];
         }
     }
     foreach ($versions as $version) {
         if (!isset($this->parsed['releases'][$version]['release_link'])) {
             drush_log(dt("Project !project does not have release notes for version !version.", array('!project' => $project_name, '!version' => $version)), LogLevel::WARNING);
             continue;
         }
         // Download the release node page and get the html as xml to explore it.
         $release_link = $this->parsed['releases'][$version]['release_link'];
         $filename = drush_download_file($release_link, drush_tempnam($project_name));
         @($dom = \DOMDocument::loadHTMLFile($filename));
         if ($dom) {
             drush_log(dt("Successfully parsed and loaded the HTML contained in the release notes' page for !project (!version) project.", array('!project' => $project_name, '!version' => $version)), LogLevel::INFO);
         } else {
             drush_log(dt("Error while requesting the release notes page for !project project.", array('!project' => $project_name)), LogLevel::ERROR);
             continue;
         }
         $xml = simplexml_import_dom($dom);
         // Extract last update time and the notes.
         $last_updated = $xml->xpath('//div[contains(@class,"views-field-changed")]');
         $last_updated = $last_updated[0]->asXML();
         $notes = $xml->xpath('//div[contains(@class,"field-name-body")]');
         $notes = !empty($notes) ? $notes[0]->asXML() : dt("There're no release notes.");
         // Build the notes header.
         $header = array();
         $header[] = '<hr>';
         $header[] = dt("> RELEASE NOTES FOR '!name' PROJECT, VERSION !version:", array('!name' => strtoupper($project_name), '!version' => $version));
         $header[] = dt("> !last_updated.", array('!last_updated' => trim(drush_html_to_text($last_updated))));
         if ($print_status) {
             $header[] = '> ' . implode(', ', $this->parsed['releases'][$version]['release_status']);
         }
         $header[] = '<hr>';
         // Finally add the release notes for the requested project to the tmpfile.
         $content = implode("\n", $header) . "\n" . $notes . "\n";
         #TODO# accept $html as a method argument
         if (!drush_get_option('html', FALSE)) {
             $content = drush_html_to_text($content, array('br', 'p', 'ul', 'ol', 'li', 'hr'));
         }
         file_put_contents($tmpfile, $content, FILE_APPEND);
     }
     #TODO# don't print! Just return the filename
     drush_print_file($tmpfile);
 }
예제 #3
0
 /**
  * Download a backup.
  *
  * @param array $backup
  *   An array from apiGetSiteEnvBackups().
  * @param string $destination
  *   The path to the destination.
  *
  * @return string
  *   The full path to the downloaded backup.
  */
 public function apiDownloadBackup($backup, $destination)
 {
     drush_log(var_export($backup, TRUE));
     $destination_tmp = drush_tempnam('download_file');
     drush_shell_exec("curl --fail -s -L -u " . $this->authEmailGet() . ":" . $this->authPasswordGet() . " --connect-timeout 30 -o %s %s", $destination_tmp, $backup['url']);
     if (!drush_file_not_empty($destination_tmp) && ($file = @file_get_contents($backup['url']))) {
         @file_put_contents($destination_tmp, $file);
     }
     if (!drush_file_not_empty($destination_tmp)) {
         return drush_set_error('SWITCHBOARD_ACQUIA_BACKUP_DL_FAIL', dt('Unable to download!'));
     }
     $destination_path = $destination . DIRECTORY_SEPARATOR . $backup['filename'];
     drush_move_dir($destination_tmp, $destination_path, TRUE);
     return $destination_path;
 }