21 require
'../core/include/init.inc';
25 $root_user =& $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
26 $GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user);
27 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
30 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
34 if (version_compare(phpversion(), 5) >= 0) {
37 $db =& $GLOBALS[
'SQ_SYSTEM']->db;
42 $select_attribute =
'select attrid from sq_ast_attr where type_code = \'page_asset_listing\' and name = \'metadata_sort_type\'';
47 if (version_compare(phpversion(), 5) >= 0) {
48 $query = $db->prepare($select_attribute);
51 }
catch (Exception $e) {
52 throw new Exception($e.getMessage());
55 $attribute_id = $db->getOne($select_attribute);
56 assert_valid_db_result($attribute_id);
60 if (empty($attribute_id)) {
61 echo
'The attribute "metadata_sort_type" for "page_asset_listing" does not exists';
67 $assets_id = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'page_asset_listing', TRUE);
69 if (empty($assets_id)) {
70 echo
'NO PAGE ASSET LISTINGS FOUND'.
"\n";
74 bam(
'All the page_asset_listing ids');
79 echo
'*****************************************'.
"\n";
80 echo
'* THE FOLLOWING ASSETS WILL BE AFFECTED *'.
"\n";
81 echo
'*****************************************'.
"\n";
85 $asset_listing_ids =
'';
86 $_tmp_assets_id = Array();
87 if (count($assets_id) > 1) {
88 foreach ($assets_id as $key => $value) {
89 $_tmp_assets_id = array_merge($_tmp_assets_id, Array($key => $db->quote((
string)$value)));
91 $asset_listing_ids = implode(
',', $_tmp_assets_id);
93 $asset_listing_ids =
"'".$assets_id[0].
"'";
97 $select =
"select atv.assetid from sq_ast_attr at, sq_ast_attr_val atv where at.name like 'metadata_sort_type' and at.attrid = atv.attrid and atv.assetid in (".$asset_listing_ids.
");";
98 $with_custom_attr_assets_id = Array();
100 if (version_compare(phpversion(), 5) >= 0) {
102 $query = $db->prepare($select);
105 }
catch (Exception $e) {
106 throw new Exception(
'Could not get the '.$e->getMessage());
108 foreach ($result as $value) {
109 $with_custom_attr_assets_id = array_merge($with_custom_attr_assets_id, Array($value[
'assetid']));
112 $result = $db->query($select);
113 assert_valid_db_result($result);
114 while (DB_OK === $result->fetchInto($row)) {
115 $with_custom_attr_assets_id = array_merge($with_custom_attr_assets_id, Array($row[
'assetid']));
121 bam(
'page_asset_listing ids of assets with custom attribute');
122 bam($with_custom_attr_assets_id);
127 $create_custom_attr_id = array_diff($assets_id, $with_custom_attr_assets_id);
129 bam(
'Assets that need to have a custom value');
130 bam($create_custom_attr_id);
134 echo
"***************************************************************\n";
135 echo
"* WARNING: DOUBLE CHECK THE SQL QUERIES BEFORE EXECUTING THEM *\n";
136 echo
"***************************************************************\n\n";
142 echo
'*****************************************************************************'.
"\n";
143 echo
'* TO SET THE METADATA SORTING OPTION TO "RAW" RUN THE FOLLOWING SQL QUERIES *'.
"\n";
144 echo
'*****************************************************************************'.
"\n\n";
147 foreach($create_custom_attr_id as $id) {
148 echo
'INSERT INTO sq_ast_attr_val(assetid, attrid, custom_val) values (\''.$id.
'\', \
''.$attribute_id.
'\', \
'raw\');'.
"\n";
153 $asset_listing_ids =
'';
154 if (count($assets_id) > 1) {
155 foreach ($assets_id as $key => $value) {
156 $assets_id[$key] = $db->quote((
string)$value);
158 $asset_listing_ids = implode(
',', $assets_id);
160 $asset_listing_ids = $assets_id[0];
166 foreach ($assets_id as $id) {
167 if (!empty($where)) {
171 $where .=
'( assetid = '.$id.
' AND attrid = \''.$attribute_id.
'\')
';
174 $update = 'UPDATE sq_ast_attr_val
set custom_val = \
'raw\' where '.$where.
';';
179 echo
'**************************************************************************************'.
"\n";
180 echo
'* TO SET THE METADATA SORTING OPTION TO "PRESENTATION" RUN THE FOLLOWING SQL QUERIES *'.
"\n";
181 echo
'**************************************************************************************'.
"\n\n";
184 foreach($create_custom_attr_id as $id) {
185 echo
'INSERT INTO sq_ast_attr_val(assetid, attrid, custom_val) values (\''.$id.
'\', \
''.$attribute_id.
'\', \
'presentation\');'.
"\n";
187 $update =
'UPDATE sq_ast_attr_val set custom_val = \'presentation\' where '.$where.
';';
191 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();