Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
cron_job_escalate_safe_trash.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/system/cron/cron_job/cron_job.inc';
19 require_once SQ_INCLUDE_PATH.'/workflow_manager.inc';
20 require_once SQ_FUDGE_PATH.'/general/datetime.inc';
21 
34 {
35 
36 
43  function __construct($assetid=0)
44  {
45  parent::__construct($assetid);
46 
47  }//end constructor
48 
49 
61  public function create(Array &$link)
62  {
63  require_once SQ_CORE_PACKAGE_PATH.'/system/system_asset_fns.inc';
64  if (!system_asset_fns_create_pre_check($this)) {
65  return FALSE;
66  }
67  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
68  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
69 
70  if ($linkid = parent::create($link)) {
71  if (!system_asset_fns_create_cleanup($this)) {
72  $linkid = FALSE;
73  }
74  }
75 
76  if ($linkid) {
77  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
78  } else {
79  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
80  }
81 
82  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
83  return $linkid;
84 
85  }//end create()
86 
87 
97  protected function _getName($short_name=FALSE)
98  {
99  return translate('cron_job_escalate_safe_trash');
100 
101  }//end _getName()
102 
103 
110  public function canClone()
111  {
112  return FALSE;
113 
114  }//end canClone()
115 
116 
125  public function canDelete()
126  {
127  return FALSE;
128 
129  }//end canDelete()
130 
131 
145  protected function _exec(&$msg)
146  {
147  $cron_mgr_assetid = $GLOBALS['SQ_SYSTEM']->am->getSystemAssetid('cron_manager');
148  $links = $GLOBALS['SQ_SYSTEM']->am->getLinks($cron_mgr_assetid, SQ_LINK_TYPE_3, 'cron_job_attempt_safe_trash');
149 
150  foreach ($links as $link) {
151  $job_assetid = $link['minorid'];
152  $job_link = $GLOBALS['SQ_SYSTEM']->am->getLink($job_assetid, SQ_LINK_NOTICE, '', TRUE, 'updating');
153 
154  $job_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($job_assetid));
155  $job_info = $job_info[$job_assetid];
156 
157  $trash_user_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($job_info['created_userid']);
158  $trash_user_info = $trash_user_info[$job_info['created_userid']];
159 
160  if (!empty($job_link)) {
161  $trashing_assetid = $job_link['minorid'];
162  $trash_errors = $GLOBALS['SQ_SYSTEM']->am->canSafeTrashAsset($trashing_assetid);
163 
164  // If there are safe trash errors
165  if (!empty($trash_errors)) {
166  $trashing_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($trashing_assetid);
167  $from = '0';
168 
169  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
170  $messages = Array();
171 
172  if (!empty($trash_errors['status'])) {
173  // unsafe status
174  $type = 'cron.safetrash.notify.status';
175  $asset_admins = $GLOBALS['SQ_SYSTEM']->am->getPermission($trashing_assetid, SQ_PERMISSION_ADMIN, TRUE);
176 
177  $replacements = Array(
178  'assetid' => $trashing_asset->id,
179  'asset_name' => $trashing_asset->name,
180  'asset_status' => get_status_description($trash_errors['status']),
181  'trash_date' => easy_datetime(iso8601_ts($job_info['created'])),
182  'trashing_user' => $trash_user_info['name'],
183  );
184 
185  if (empty($asset_admins)) $asset_admins = Array(0);
186  $msg = $ms->newMessage($asset_admins, $type, $replacements);
187  $messages[] = $msg;
188  }
189 
190  if (!empty($trash_errors['links'])) {
191  // unsafe links
192  $type = 'cron.safetrash.notify.links';
193 
194  foreach ($trash_errors['links'] as $link) {
195  $asset_admins = $GLOBALS['SQ_SYSTEM']->am->getPermission($link['majorid'], SQ_PERMISSION_ADMIN, TRUE);
196  $linked_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['majorid']);
197 
198  $replacements = Array(
199  'assetid' => $trashing_asset->id,
200  'asset_name' => $trashing_asset->name,
201  'link_assetid' => $linked_asset->id,
202  'link_asset_name' => $linked_asset->name,
203  'trash_date' => easy_datetime(iso8601_ts($job_info['created'])),
204  'trashing_user' => $trash_user_info['name'],
205  );
206 
207  if (empty($asset_admins)) $asset_admins = Array(0);
208  $msg = $ms->newMessage($asset_admins, $type, $replacements);
209  $messages[] = $msg;
210  }
211 
212 
213  }
214 
215  if (!empty($trash_errors['children'])) {
216  // unsafe children
217  $type = 'cron.safetrash.notify.children';
218 
219  foreach ($trash_errors['children'] as $link) {
220  $asset_admins = $GLOBALS['SQ_SYSTEM']->am->getPermission($link['minorid'], SQ_PERMISSION_ADMIN, TRUE);
221  $linked_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($link['minorid']);
222 
223  $replacements = Array(
224  'assetid' => $trashing_asset->id,
225  'asset_name' => $trashing_asset->name,
226  'link_assetid' => $linked_asset->id,
227  'link_asset_name' => $linked_asset->name,
228  'trash_date' => easy_datetime(iso8601_ts($job_info['created'])),
229  'trashing_user' => $trash_user_info['name'],
230  );
231 
232  if (empty($asset_admins)) $asset_admins = Array(0);
233  $msg = $ms->newMessage($asset_admins, $type, $replacements);
234  $messages[] = $msg;
235  }
236  }
237 
238  $ms->send($messages);
239 
240  }//end if trash errors
241  }//end if job link not empty
242  }//end foreach cron job link
243 
244  return SQ_CRON_JOB_COMPLETED;
245 
246  }//end _exec()
247 
248 
259  public function run()
260  {
261  $res = parent::run();
262  if ($res & SQ_CRON_JOB_REMOVE) {
263  $res = $res - SQ_CRON_JOB_REMOVE;
264  }
265  return $res;
266 
267  }//end run()
268 
269 
270 }//end class
271 
272 
273 
274 ?>