0e6ae6eb46c37e7bbfe79880a7f881da07f7a271
[yaffs-website] / vendor / drush / drush / lib / Drush / UpdateService / StatusInfoDrupal7.php
1 <?php
2
3 /**
4  * @file
5  * Implementation of 'drupal' update_status engine for Drupal 7.
6  */
7
8 namespace Drush\UpdateService;
9
10 class StatusInfoDrupal7 extends StatusInfoDrupal8 {
11
12   /**
13    * {@inheritdoc}
14    */
15   function lastCheck() {
16     return variable_get('update_last_check', 0);
17   }
18
19   /**
20    * {@inheritdoc}
21    */
22   function beforeGetStatus(&$projects, $check_disabled) {
23     // If check-disabled option was provided, alter Drupal settings temporarily.
24     // There's no other way to hook into this.
25     if (!is_null($check_disabled)) {
26       global $conf;
27       $this->update_check_disabled = $conf['update_check_disabled'];
28       $conf['update_check_disabled'] = $check_disabled;
29     }
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   function afterGetStatus(&$update_info, $projects, $check_disabled) {
36     // Restore Drupal settings.
37     if (!is_null($check_disabled)) {
38       global $conf;
39       $conf['update_check_disabled'] = $this->update_check_disabled;
40       unset($this->update_check_disabled);
41     }
42
43     // update.module sets a different project type
44     // for disabled projects. Here we normalize it.
45     if ($check_disabled) {
46       foreach ($update_info as $key => $project) {
47         if (in_array($project['project_type'], array('module-disabled', 'theme-disabled'))) {
48           $update_info[$key]['project_type'] = substr($project['project_type'], 0, strpos($project['project_type'], '-'));
49         }
50       }
51     }
52   }
53
54   /**
55    * Obtains release info for all installed projects via update.module.
56    *
57    * @see update_get_available().
58    * @see update_manual_status().
59    */
60   protected function getAvailableReleases() {
61     // Force to invalidate some caches that are only cleared
62     // when visiting update status report page. This allow to detect changes in
63     // .info files.
64     _update_cache_clear('update_project_data');
65     _update_cache_clear('update_project_projects');
66
67     // From update_get_available(): Iterate all projects and create a fetch task
68     // for those we have no information or is obsolete.
69     $available = _update_get_cached_available_releases();
70
71     module_load_include('inc', 'update', 'update.compare');
72     $update_projects = update_get_projects();
73
74     foreach ($update_projects as $key => $project) {
75       if (empty($available[$key])) {
76         update_create_fetch_task($project);
77         continue;
78       }
79       if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) {
80         $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
81       }
82       if (empty($available[$key]['releases'])) {
83         $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
84       }
85       if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UPDATE_FETCH_PENDING) {
86         update_create_fetch_task($project);
87       }
88     }
89
90     // Set a batch to process all pending tasks.
91     $batch = array(
92       'operations' => array(
93         array('update_fetch_data_batch', array()),
94       ),
95       'finished' => 'update_fetch_data_finished',
96       'file' => drupal_get_path('module', 'update') . '/update.fetch.inc',
97     );
98     batch_set($batch);
99     drush_backend_batch_process();
100
101     // Clear any error set by a failed update fetch task. This avoid rollbacks.
102     drush_clear_error();
103
104     // Calculate update status data.
105     $available = _update_get_cached_available_releases();
106     return $available;
107   }
108 }
109