18 require_once SQ_CORE_PACKAGE_PATH.
'/report/report_edit_fns.inc';
19 require_once SQ_FUDGE_PATH.
'/general/general.inc';
41 parent::__construct();
59 require_once SQ_FUDGE_PATH.
'/general/text.inc';
60 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
61 $owner = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($job->_running_vars[
'assetid'],
'report_safe_trash');
63 $asset_types = $owner->getAllowedAssetTypeMap();
65 if (!isset($job->_running_vars[
'results'])) {
66 $job->_running_vars[
'todo'] = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($this->
getRootAssetid($owner));
67 $job->_running_vars[
'done'] = Array();
68 $job->_running_vars[
'results'] = Array();
70 if (!is_dir($owner->data_path)) {
71 if (!create_directory($owner->data_path)) {
72 trigger_localised_error(
'CORE0198', E_USER_WARNING);
76 $temp_file = fopen($owner->data_path.
'/report.tmp',
'w');
77 if ($temp_file === FALSE) {
78 trigger_localised_error(
'CORE0201', E_USER_WARNING);
81 fwrite($temp_file,
'<?xml version="1.0" encoding="'.SQ_CONF_DEFAULT_CHARACTER_SET.
'"?>'.
"\n");
82 fwrite($temp_file,
"<assets>\n");
84 $temp_file = fopen($owner->data_path.
'/report.tmp',
'a');
85 if ($temp_file === FALSE) {
86 trigger_localised_error(
'CORE0201', E_USER_WARNING);
90 if (!empty($job->_running_vars[
'todo'])) {
92 $keys = array_keys($job->_running_vars[
'todo']);
93 $assetid = array_shift($keys);
94 $asset_type = $job->_running_vars[
'todo'][$assetid][0][
'type_code'];
95 unset($job->_running_vars[
'todo'][$assetid]);
96 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
98 if (!is_null($asset) && !($asset instanceof
Root_Folder)) {
101 if (empty($asset_types) || isset($asset_types[$asset->type()])) {
102 $job_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'cron_job_attempt_safe_trash', TRUE,
'updating',
'minor');
105 $cron_job = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($job_link[
'majorid']);
106 $step_data[
'message'] = translate(
'core_checking_for_metadata', $asset->name);
108 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
109 $field_values = $mm->getMetadataFieldValues($asset->id);
110 $trash_errors = $GLOBALS[
'SQ_SYSTEM']->am->canSafeTrashAsset($asset->id);
114 $content =
"\t".
'<asset assetid="'.$asset->id.
'" name="'.htmlspecialchars($asset->name).
'" short_name="'.htmlSpecialChars($asset->short_name).
'" type_code="'.$asset->type().
'" status="'.$asset->status.
'" marked_since="'.$cron_job->created.
'">';
116 if (!empty($trash_errors[
'links'])) {
117 $content .=
'<unsafe_links>';
118 foreach ($trash_errors[
'links'] as $link) {
119 $content .=
' <assetid>'.$link[
'majorid'].
'</assetid>';
121 $content .=
'</unsafe_links>';
124 if (!empty($trash_errors[
'children'])) {
125 $content .=
'<unsafe_children>';
126 foreach ($trash_errors[
'children'] as $link) {
127 $content .=
' <assetid>'.$link[
'minorid'].
'</assetid>';
129 $content .=
'</unsafe_children>';
132 $content .=
'</asset>'.
"\n";
135 if (!empty($trash_errors)) fwrite($temp_file, $content);
137 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid).
' - NO JOB';
140 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
143 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
146 $step_data[
'message'] = translate(
'hipo_skipping_asset', $assetid);
147 $job->
_addError(translate(
'core_cannot_generate_incomplete_metadata_report', $assetid));
151 $job->_running_vars[
'done'][] = $assetid;
155 if (empty($job->_running_vars[
'todo']) && !$job->_running_vars[
'complete']) {
156 $step_data[
'percent_done'] = 100;
157 $step_data[
'complete'] = TRUE;
160 fwrite($temp_file,
"</assets>\n");
161 if (!copy($owner->data_path.
'/report.tmp', $owner->data_path.
'/report.xml')) {
162 trigger_localised_error(
'CORE0200', E_USER_WARNING);
165 if (!unlink($owner->data_path.
'/report.tmp')) {
166 trigger_localised_error(
'CORE0199', E_USER_WARNING);
169 $total = count($job->_running_vars[
'todo']) + count($job->_running_vars[
'done']);
170 $step_data[
'percent_done'] = (count($job->_running_vars[
'done']) / $total) * 100;
171 $step_data[
'complete'] = FALSE;
191 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
192 $report_path = $asset->data_path.
'/report.xml';
193 if (!is_file($report_path)) {
194 echo translate(
'report_not_generated');
199 $root =
new SimpleXMLElement($report_path, LIBXML_NOCDATA, TRUE);
200 }
catch (Exception $e) {
201 throw new Exception(
'Unable to parse report file "'.$report_path.
'": '.$e->getMessage());
206 $missing_fields = Array();
208 foreach ($root->asset as $result) {
209 $id = (int) $result->attributes()->assetid;
210 $missing_fields[$id][
'since'] = (string) $result->attributes()->marked_since;
212 foreach ($result->unsafe_children as $unsafe_children) {
213 foreach ($unsafe_children->assetid as $unsafe_assetid) {
214 $missing_fields[$id][
'children'][] = (int) $unsafe_assetid;
217 foreach ($result->unsafe_links as $unsafe_links) {
218 foreach ($unsafe_links->assetid as $unsafe_assetid) {
219 $missing_fields[$id][
'links'][] = (int) $unsafe_assetid;
224 if (SQ_IN_BACKEND || SQ_IN_LIMBO) {
225 echo
'<b>Note</b> The current safe trash report is shown below. You can regenerate this report on the <a href="'.$asset->getBackendHref(
'details').
'">details screen</a>.';
229 $o->
openSection(translate(
'report_safe_trash_section_status'));
231 if (empty($missing_fields)) {
232 echo
'NO ASSET FOUND';
235 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
237 <table
class=
"sq-backend-table">
239 <td
class=
"sq-backend-table-header"><?php echo translate(
'asset'); ?></td>
240 <td
class=
"sq-backend-table-header" style=
"width: 180px"><?php echo translate(
'report_safe_trash_marked_since'); ?></td>
241 <td
class=
"sq-backend-table-header" style=
"width: 150px"><?php echo translate(
'status'); ?></td>
242 <td
class=
"sq-backend-table-header" style=
"width: 150px"><?php echo translate(
'report_safe_trash_unsafe_links'); ?></td>
243 <td
class=
"sq-backend-table-header" style=
"width: 150px"><?php echo translate(
'report_safe_trash_unsafe_children'); ?></td>
246 foreach ($missing_fields as $assetid => $fields) {
249 $asset_tmp = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'', TRUE);
251 if (is_null($asset_tmp)) {
253 $asset_string =
'Unknown asset #'.$assetid;
254 $asset_bg =
'FFFFFF';
257 $asset_type = $asset_tmp->type();
258 $asset_bg = get_asset_status_icon($asset_tmp->status);
259 $asset_status = get_status_description($asset_tmp->status);
260 $asset_url = $asset_tmp->getBackendHref(
'metadata');
261 $asset_string =
'<a href="'.$asset_tmp->getBackendHref(
'details').
'" title="'.$asset_tmp->name.
'">'.ellipsisize($asset_tmp->name, 40).
'</a>';
266 <td
class=
"sq-backend-table-cell" style=
"padding-right: 1px;">
268 if (!empty($asset_type)) {
269 echo get_asset_tag_line($asset_tmp->id,
'details');
273 <td
class=
"sq-backend-table-cell">
274 <?php echo easy_datetime((
int)$missing_fields[$asset_tmp->id][
'since']); ?>
276 <td
class=
"sq-backend-table-cell" style=
"padding-right: 1px;">
278 if ($asset_tmp->status >= SQ_STATUS_LIVE) {
280 <span
class=
"sq-backend-warning">
284 <?php echo $asset_bg; ?><?php echo $asset_status; ?>
286 if ($asset_tmp->status >= SQ_STATUS_LIVE) {
293 <td
class=
"sq-backend-table-cell">
295 if (empty($missing_fields[$asset_tmp->id][
'links'])) {
296 echo translate(
'none');
299 <ul style=
"list-style-type: none; padding-left: 0; margin-left: 0;">
301 foreach ($missing_fields[$asset_tmp->id][
'links'] as $linked_assetid) {
303 <li
class=
"sq-backend-warning"><?php echo get_asset_tag_line($linked_assetid,
'details'); ?></li>
312 <td
class=
"sq-backend-table-cell">
314 if (empty($missing_fields[$asset_tmp->id][
'children'])) {
315 echo translate(
'none');
318 <ul style=
"list-style-type: none; padding-left: 0; margin-left: 0;">
320 foreach ($missing_fields[$asset_tmp->id][
'children'] as $linked_assetid) {
322 <li
class=
"sq-backend-warning"><?php echo get_asset_tag_line($linked_assetid,
'details'); ?></li>
355 $types = $asset->
attr(
'types');
357 echo translate(
'core_no_types_defined');
362 <table
class=
"sq-backend-table">
364 <td
class=
"sq-backend-table-header"><?php echo translate(
'asset_type'); ?></td>
365 <td
class=
"sq-backend-table-header"><?php echo translate(
'inherit_types'); ?></td>
369 <td
class=
"sq-backend-table-header"><?php echo translate(
'remove_question'); ?></td>
375 foreach ($types as $type => $inherit) {
378 <td
class=
"sq-backend-table-cell">
380 echo ucwords(str_replace(
'_',
' ', $type));
383 <td
class=
"sq-backend-table-cell">
386 check_box($prefix.
"_inherit_types[$type]", $type, $inherit);
388 echo ($inherit) ? translate(
'yes') : translate(
'no');
395 <td
class=
"sq-backend-table-cell">
397 check_box($prefix.
"_remove[$type]", $type, FALSE);
425 $types = $asset->
attr(
'types');
428 if (isset($_POST[$prefix.
'_remove'])) {
430 foreach ($_POST[$prefix.
'_remove'] as $type) {
431 if (isset($types[$type])) unset($types[$type]);
435 $inherit_types = array_get_index($_POST, $prefix.
'_inherit_types', Array());
436 foreach ($types as $key => $val) {
437 $types[$key] = isset($inherit_types[$key]) ? TRUE : FALSE;
461 $types = $GLOBALS[
'SQ_SYSTEM']->am->getTypeList();
462 $types = array_diff($types, $asset->
attr(
'types'));
465 $uc_types = Array(
'' =>
'');
466 foreach ($types as $type) {
467 $uc_types[$type] = ucwords(str_replace(
'_',
' ', $type));
469 combo_box($prefix.
'_new_type', $uc_types, FALSE,
'');
486 if (isset($_POST[$prefix.
'_new_type'])) {
487 $type = trim($_POST[$prefix.
'_new_type']);
489 if (empty($type))
return FALSE;
491 $types = $asset->
attr(
'types');
493 if (!isset($types[$type])) {
494 $types[$type] = TRUE;