17 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
49 public static function execute($settings, &$state)
51 if (empty($state[
'asset'])) {
53 if (empty($state[
'assetid'])) {
56 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
59 if (is_null($state[
'asset']))
return FALSE;
61 $am = $GLOBALS[
'SQ_SYSTEM']->am;
64 'assetid' => $state[
'asset']->
id,
69 $urls = $state[
'asset']->getURLs();
70 if (empty($urls))
return $result;
74 $sites = $am->getParents($state[
'asset']->
id,
'site');
75 if (empty($sites))
return $result;
79 foreach (array_keys($sites) as $site_id) {
81 $site = $am->getAsset($site_id);
82 $site_urls = $site->getSiteURLs();
84 if (empty($site_urls)) {
88 $tiny_urls = array_merge($tiny_urls, $site_urls);
94 $mapped_tiny_urls = Array();
95 if (!empty($tiny_urls)) {
96 foreach ($tiny_urls as $tiny_url) {
98 foreach ($urls as $url_info) {
99 if ( ($pos = strpos($url_info[
'url'], $tiny_url[
'url'].
'/')) === 0 ) {
101 $protocols = Array();
102 if ($url_info[
'http'] == 1) {
103 $protocols[] =
'http://';
106 if ($url_info[
'https'] == 1) {
107 $protocols[] =
'https://';
110 for ($i=0; $i<count($protocols); $i++) {
111 $old_url = $protocols[$i].$tiny_url[
'url'].
'/'.$state[
'asset']->id;
112 $mapped_tiny_urls[$old_url] = $protocols[$i].$url_info[
'url'];
126 if (!empty($mapped_tiny_urls)) {
129 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
130 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
132 $old_urls = array_keys($mapped_tiny_urls);
139 }
catch (Exception $e) {
140 throw new Exception(
'Unable to delete remap urls due to the following database error:'.$e->getMessage());
143 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
144 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
146 $rm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'remap_manager');
147 foreach ($mapped_tiny_urls as $old_url => $new_url) {
148 $remap_result = $rm->addRemapURL($old_url, $new_url);
149 switch ($remap_result) {
151 trigger_error(
'CORE0271', E_USER_WARNING);
154 trigger_error(
'CORE0272', E_USER_WARNING, $old_url);
160 $result[
'remap_urls'] = $mapped_tiny_urls;
176 public static function getInterface($settings, $prefix, $write_access=FALSE)
179 echo translate(
'trigger_action_add_remap_message');
180 return ob_get_clean();
194 public static function getLocks($settings, &$state)
196 return Array($state[
'assetid'] => Array(
'lookups'));