Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_remove_future_lineage_cron.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 define('SQ_REMOVE_FUTURE_LINEAGE_CRON_ADD', 1);
19 define('SQ_REMOVE_FUTURE_LINEAGE_CRON_DELETE', 2);
20 define('SQ_REMOVE_FUTURE_LINEAGE_CRON_BOTH', 3);
21 
31 {
32 
33 
51  public static function execute($settings, &$state)
52  {
53  // Check settings
54  if (empty($settings['job_type'])) {
55  // If no settings, fail
56  return FALSE;
57  }
58 
59  if (empty($state['asset'])) {
60  // Grab the asset if assetid is given, but not the asset.
61  if (empty($state['assetid'])) {
62  return FALSE;
63  } else {
64  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
65  }
66  }
67 
68  $cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
69  if (is_null($cron_mgr)) return FALSE;
70 
71  $GLOBALS['SQ_SYSTEM']->am->includeAsset('cron_job_future_lineage');
72  $future_lineage_jobs = Cron_Job_Future_Lineage::getActiveJobs($state['asset']);
73  if (empty($future_lineage_jobs)) return TRUE;
74 
75  $jobids = Array();
76 
77  foreach ($future_lineage_jobs as $job) {
78 
79  $job_type = $job->attr('link_info') ? SQ_REMOVE_FUTURE_LINEAGE_CRON_ADD : SQ_REMOVE_FUTURE_LINEAGE_CRON_DELETE;
80 
81  if ($settings['job_type'] == SQ_REMOVE_FUTURE_LINEAGE_CRON_BOTH || $settings['job_type'] == $job_type) {
82  if (!$cron_mgr->removeJob($job)) {
83  trigger_localised_error('CORE0308', E_USER_WARNING, $job->id);
84  } else {
85  $jobids[] = $job->id;
86  }
87  }//end if
88  }//end foreach
89 
90  return Array(
91  'jobids' => $jobids,
92  );
93 
94  }//end execute()
95 
96 
107  public static function getInterface($settings, $prefix, $write_access=FALSE)
108  {
109  if (empty($settings['job_type'])) {
110  // set to default
111  $selected_type = SQ_REMOVE_FUTURE_LINEAGE_CRON_BOTH;
112  } else {
113  $selected_type = $settings['job_type'];
114  }
115 
117 
118 
119  if (!$write_access) {
120  $form_element_extras = 'disabled="disabled"';
121  } else {
122  $form_element_extras = '';
123  }
124 
125  ob_start();
126  echo translate('trigger_remove_future_lineage_cron');
127  combo_box($prefix.'[job_type]', $jobs_types, FALSE, $selected_type, NULL, $form_element_extras);
128  $html = ob_get_contents();
129  ob_end_clean();
130 
131  return $html;
132 
133  }//end getInterface()
134 
135 
147  public static function processInterface(&$settings, $request_data)
148  {
149  $job_type = array_get_index($request_data, 'job_type', FALSE);
150  if (!$job_type) {
151  return 'Cron job type not specified';
152  }
153 
155 
156  // check if the job_type is valid
157  if (!isset($jobs_types[$job_type])) {
158  return 'Specified cron job type is invalid';
159  }
160  $settings['job_type'] = $job_type;
161 
162  return FALSE;
163 
164  }//end processInterface()
165 
166 
175  protected static function _getCronJobTypeList()
176  {
177  return Array(
178  SQ_REMOVE_FUTURE_LINEAGE_CRON_ADD => "Create",
179  SQ_REMOVE_FUTURE_LINEAGE_CRON_DELETE => "Delete",
180  SQ_REMOVE_FUTURE_LINEAGE_CRON_BOTH => "Create/Delete",
181  );
182 
183  }//end _getCronJobTypeList()
184 
185 
186 
187 }//end class
188 
189 ?>