17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
51 public static function execute($settings, &$state)
54 if (!isset($settings[
'removefromto']) && !isset($settings[
'removetofrom']))
return FALSE;
55 $remove_from_to = ($settings[
'removefromto'] ==
'1') ? TRUE : FALSE;
56 $remove_to_from = ($settings[
'removetofrom'] ==
'1') ? TRUE : FALSE;
59 if (empty($state[
'asset'])) {
61 if (empty($state[
'assetid'])) {
64 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
67 if (is_null($state[
'asset']))
return FALSE;
70 $lock_acquired = ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($state[
'asset']->
id,
'lookups') == 1);
73 $urls = $state[
'asset']->getURLs();
78 throw new Exception(
'Unable to delete remaps due to database error: '.$e->getMessage());
82 $never_delete_urls = Array();
83 foreach ($results as $index => $result) {
84 if($result[
'never_delete']) {
85 $never_delete_urls[$result[$remove_from_to ?
'remap_url' :
'url']] = 1;
89 foreach ($urls as $url) {
91 if ($url[
'http'] ==
'1' && !isset($never_delete_urls[
'http://'.$url[
'url']])) {
92 $address[] =
'http://'.$url[
'url'];
94 if ($url[
'https'] ==
'1' && !isset($never_delete_urls[
'https://'.$url[
'url']])) {
95 $address[] =
'https://'.$url[
'url'];
98 if (!empty($address)) {
101 if ($remove_from_to) {
102 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
103 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
105 $bind_vars = Array(
'urls' => $address);
108 throw new Exception(
'Unable to delete remaps due to database error: '.$e->getMessage());
110 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
111 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
115 if ($remove_to_from) {
116 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
117 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
119 $bind_vars = Array(
'urls' => $address);
122 throw new Exception(
'Unable to delete remaps due to database error: '.$e->getMessage());
124 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
125 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
131 if ($lock_acquired) {
132 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($state[
'asset']->
id,
'lookups');
148 public static function getInterface($settings, $prefix, $write_access=FALSE)
150 $remove_from_to = array_get_index($settings,
'removefromto', 1);
151 $remove_to_from = array_get_index($settings,
'removetofrom', 0);
154 echo translate(
'trigger_schema_remove_remaps_message');
157 check_box($prefix.
'[removefromto]',
'1', $remove_from_to,
'');
158 label(translate(
'trigger_schema_remove_from_to_remaps_message'));
160 check_box($prefix.
'[removetofrom]',
'1', $remove_to_from,
'');
161 label(translate(
'trigger_schema_remove_to_from_remaps_message'));
163 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($remove_from_to ?
'tick' :
'cross').
'.gif" alt="'.($remove_from_to ? translate(
'yes') : translate(
'no')).
'" /> ';
164 echo translate(
'trigger_schema_remove_from_to_remaps_message');
166 echo
'<img src="'.sq_web_path(
'lib').
'/web/images/'.($remove_to_from ?
'tick' :
'cross').
'.gif" alt="'.($remove_to_from ? translate(
'yes') : translate(
'no')).
'" /> ';
167 echo translate(
'trigger_schema_remove_to_from_remaps_message');
170 $output = ob_get_contents();
191 $settings[
'removefromto'] = array_get_index($request_data,
'removefromto', FALSE);
192 $settings[
'removetofrom'] = array_get_index($request_data,
'removetofrom', FALSE);
207 public static function getLocks($settings, &$state)
209 return Array($state[
'assetid'] => Array(
'lookups'));