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';
45 parent::__construct($assetid);
63 require_once SQ_CORE_PACKAGE_PATH.
'/system/system_asset_fns.inc';
64 if (!system_asset_fns_create_pre_check($this)) {
67 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
68 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
70 if ($linkid = parent::create($link)) {
71 if (!system_asset_fns_create_cleanup($this)) {
77 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
79 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
82 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
99 return translate(
'cron_job_escalate_safe_trash');
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');
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');
154 $job_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($job_assetid));
155 $job_info = $job_info[$job_assetid];
157 $trash_user_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($job_info[
'created_userid']);
158 $trash_user_info = $trash_user_info[$job_info[
'created_userid']];
160 if (!empty($job_link)) {
161 $trashing_assetid = $job_link[
'minorid'];
162 $trash_errors = $GLOBALS[
'SQ_SYSTEM']->am->canSafeTrashAsset($trashing_assetid);
165 if (!empty($trash_errors)) {
166 $trashing_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($trashing_assetid);
169 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
172 if (!empty($trash_errors[
'status'])) {
174 $type =
'cron.safetrash.notify.status';
175 $asset_admins = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($trashing_assetid, SQ_PERMISSION_ADMIN, TRUE);
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'],
185 if (empty($asset_admins)) $asset_admins = Array(0);
186 $msg = $ms->newMessage($asset_admins, $type, $replacements);
190 if (!empty($trash_errors[
'links'])) {
192 $type =
'cron.safetrash.notify.links';
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']);
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'],
207 if (empty($asset_admins)) $asset_admins = Array(0);
208 $msg = $ms->newMessage($asset_admins, $type, $replacements);
215 if (!empty($trash_errors[
'children'])) {
217 $type =
'cron.safetrash.notify.children';
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']);
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'],
232 if (empty($asset_admins)) $asset_admins = Array(0);
233 $msg = $ms->newMessage($asset_admins, $type, $replacements);
238 $ms->send($messages);
244 return SQ_CRON_JOB_COMPLETED;
261 $res = parent::run();
262 if ($res & SQ_CRON_JOB_REMOVE) {
263 $res = $res - SQ_CRON_JOB_REMOVE;