17 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
54 public static function execute($settings, &$state)
58 if (!isset($settings[
'url']))
return FALSE;
61 if ($settings[
'url'] ==
'')
return FALSE;
63 $settings[
'http'] = array_get_index($settings,
'http', 0);
64 $settings[
'https'] = array_get_index($settings,
'https', 0);
65 $settings[
'base_contextid'] = array_get_index($settings,
'base_contextid', 0);
67 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
69 if (array_key_exists($settings[
'base_contextid'], $all_contexts) === FALSE) {
70 $settings[
'base_contextid'] = 0;
74 if (!$settings[
'http'] && !$settings[
'https']) {
78 if (empty($state[
'asset'])) {
80 if (empty($state[
'assetid'])) {
83 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
86 if (is_null($state[
'asset']))
return FALSE;
89 if (!($state[
'asset'] instanceof
Site)) {
90 trigger_error(
'Unable to add URL for a '.$state[
'asset']->
type().
' asset', E_USER_NOTICE);
96 $urls = $state[
'asset']->getSiteURLs();
97 foreach ($urls as $key => $value) {
98 if ($value[
'url'] == $settings[
'url']) {
99 if ($value[
'http'] == $settings[
'http'] && $value[
'https'] == $settings[
'https']) {
110 'url' => $settings[
'url'],
111 'http' => $settings[
'http'],
112 'https' => $settings[
'https'],
113 'base_contextid' => $settings[
'base_contextid'],
117 $old_urls = $state[
'asset']->getSiteURLs();
118 switch ($state[
'asset']->saveWebURLs($urls)) {
129 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
130 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
133 foreach ($urls as $urlid => $url_data) {
135 if (!isset($old_urls[$urlid]) || $old_urls[$urlid]==$url_data) {
144 'url' => strip_url($urls[$urlid][
'url']),
148 }
catch (Exception $e) {
149 throw new Exception(
'Unable to update URL: '.strip_url($urls[$urlid][
'url']).
' for urlid: '.$urlid.
' due to database error: '.$e->getMessage());
153 foreach (Array(
'sq_ast_lookup_value',
'sq_ast_lookup') as $tablename) {
155 if ($urls[$urlid][
'url'] == $old_urls[$urlid][
'url']) {
161 url = :url || SUBSTR(url, :substr_arg)
163 (url LIKE :old_url_like OR url LIKE :old_url_like_slash)';
166 if ($tablename ==
'sq_ast_lookup') {
167 $sql .=
' AND root_urlid = :urlid';
168 }
else if ($tablename ==
'sq_ast_lookup_value') {
169 $sql .=
' AND url IN (
175 sq_ast_lookup_value v ON ((l.url = v.url) OR (l.url || \'/\' = v.url))
177 l.root_urlid = :urlid
189 }
catch (Exception $e) {
190 throw new Exception(
'Unable to update this old URL: '.$old_urls[$urlid][
'url'].
' with this new URL: '.$urls[$urlid][
'url'].
' due to database error: '.$e->getMessage());
195 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
196 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
204 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
205 $vars = Array(
'assetids' => Array($state[
'asset']->
id));
206 $hh->freestyleHipo(
'hipo_job_update_lookups', $vars);
210 'assetid' => $state[
'asset']->
id,
211 'url' => $settings[
'url'],
212 'http' => $settings[
'http'],
213 'https' => $settings[
'https'],
214 'base_contextid' => $settings[
'base_contextid'],
230 public static function getInterface($settings, $prefix, $write_access=FALSE)
234 $url = array_get_index($settings,
'url',
'');
235 $http = array_get_index($settings,
'http',
'');
236 $https = array_get_index($settings,
'https',
'');
237 $base_contextid = array_get_index($settings,
'base_contextid', 0);
239 echo translate(
'add_url').
' ';
241 text_box($prefix.
'[url]', $url, 20);
243 check_box($prefix.
'[http]',
'1', $http);
244 echo
' HTTP ';
245 check_box($prefix.
'[https]',
'1', $https);
246 echo
' HTTPS ';
248 echo
'<b>'.$url.
'</b>';
251 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
252 if (count($all_contexts) > 1) {
254 if (array_key_exists($base_contextid, $all_contexts) === FALSE) {
259 foreach ($all_contexts as $contextid => $context_data) {
260 $options[$contextid] = $context_data[
'name'];
262 combo_box($prefix.
'[base_contextid]', $options, FALSE, $base_contextid);
265 return ob_get_clean();
285 $url = array_get_index($request_data,
'url',
'');
287 if ($url ==
'')
return translate(
'url_not_specified');
288 $settings[
'url'] = $url;
291 $http = array_get_index($request_data,
'http', 0);
292 $https = array_get_index($request_data,
'https', 0);
293 $base_contextid = (int)array_get_index($request_data,
'base_contextid', 0);
294 if (!$http && !$https) {
295 return translate(
'protocol_not_specified');
298 $settings[
'http'] = ($http ==
'1') ?
'1' :
'0';
299 $settings[
'https'] = ($https ==
'1') ?
'1' :
'0';
315 public static function getLocks($settings, &$state)
317 return Array($state[
'assetid'] => Array(
'lookups'));