Esempio n. 1
0
 /**
  * @param string $extension
  *
  * @return array Context result generated by Drupal.
  *
  * @throws Oxygen_Exception
  *
  * @see update_authorize_run_update()
  */
 public function updateExtension($extension)
 {
     module_load_include('inc', 'update', 'update.manager');
     drupal_get_updaters();
     $directory = _update_manager_extract_directory();
     $projectLocation = $directory . '/' . $extension;
     $updater = Updater::factory($projectLocation);
     $projectRealLocation = drupal_realpath($projectLocation);
     // If the owner of the directory we extracted is the same as the
     // owner of our configuration directory (e.g. sites/default) where we're
     // trying to install the code, there's no need to prompt for FTP/SSH
     // credentials. Instead, we instantiate a FileTransferLocal and invoke
     // update_authorize_run_install() directly.
     if (fileowner($projectRealLocation) !== fileowner(DRUPAL_ROOT . '/' . conf_path())) {
         throw new Oxygen_Exception(Oxygen_Exception::PROJECT_MANAGER_FILE_SYSTEM_NOT_WRITABLE, array('projectOwner' => fileowner($projectRealLocation), 'siteOwner' => fileowner(conf_path())));
     }
     module_load_include('inc', 'update', 'update.authorize');
     // @TODO: Implement other file transfer types.
     $fileTransfer = new FileTransferLocal(DRUPAL_ROOT);
     update_authorize_batch_copy_project($extension, get_class($updater), $projectRealLocation, $fileTransfer, $context);
     // Reset the cache for this extension only, so we may immediately update the dashboard.
     // Hacky way to do it, but most efficient.
     module_load_include('inc', 'update', 'update.fetch');
     module_load_include('inc', 'update', 'update.compare');
     _update_cache_clear('update_project_projects');
     _update_cache_clear('update_project_data');
     $projects = update_get_projects();
     _update_process_fetch_task($projects[$extension]);
     return $context;
 }
 public function doInstallUpdate($update_row)
 {
     // Pull Projects
     $projects = update_get_projects();
     // Pull Available Releases
     $packages = db_select('cache_update', 'cu')->fields('cu')->condition('cid', 'available_releases::%', 'LIKE')->execute()->fetchAllAssoc('cid');
     // Find & Process Package
     foreach ($packages as $package) {
         // Unserialize Store
         $package->data = unserialize($package->data);
         $project = isset($projects[$package->data['short_name']]) ? $projects[$package->data['short_name']] : null;
         $package_update = reset($package->data['releases']);
         $package_uid = $project['project_type'] . ':' . $project['name'] . ':' . $package_update['version'];
         // Match Package
         if ($update_row->update_id == $package_uid) {
             // Type Switch
             switch ($update_row->type) {
                 case 'core':
                     $this->caller->out(' - Error: Core Updates Not Supported');
                     break;
                 case 'module':
                 case 'theme':
                     // Download Package
                     if (!($local_cache = update_manager_file_get($package_update['download_link']))) {
                         $this->caller->out(' - Error: Failed to download ' . $project['name'] . ' from ' . $package_update['download_link']);
                         return false;
                     }
                     // Extract it.
                     $extract_directory = _update_manager_extract_directory();
                     try {
                         update_manager_archive_extract($local_cache, $extract_directory);
                     } catch (Exception $e) {
                         $this->caller->out(' - Error: ' . $e->getMessage());
                         return false;
                     }
                     // Verify it.
                     $archive_errors = update_manager_archive_verify($project['name'], $local_cache, $extract_directory);
                     if (!empty($archive_errors)) {
                         foreach ($archive_errors as $key => $error) {
                             $this->caller->out(' - Error: ' . $error);
                         }
                         return false;
                     }
                     // Load Updater
                     $project_folder = $extract_directory . '/' . $project['name'];
                     try {
                         $updater = Updater::factory($project_folder);
                     } catch (Exception $e) {
                         $this->caller->out(' - Error: ' . $e->getMessage());
                         return false;
                     }
                     $context = array('results' => array());
                     // Run Updater
                     update_authorize_batch_copy_project($project['name'], get_class($updater), drupal_realpath($project_folder), new FileTransferLocal(DRUPAL_ROOT), $context);
                     // Verify
                     if (empty($context['finished'])) {
                         $message = isset($context['results']['log'][$project['name']]) ? reset($context['results']['log'][$project['name']])['message'] : 'Unknown Installer Error';
                         $this->caller->out(' - Error: ' . $message);
                         return false;
                     } else {
                         $this->caller->out(' - ' . ucfirst($update_row->type) . ' installed successfully');
                     }
                     break;
             }
         }
     }
     // Return
     return true;
 }