17 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
54 public static function execute($settings, &$state)
56 if (empty($state[
'asset'])) {
58 if (empty($state[
'assetid'])) {
61 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
65 $use_direct_parent_sites = array_get_index($settings,
'use_direct_parent_sites', 0);
67 if (($use_direct_parent_sites == 0) && (empty($settings[
'site_assetid']) || !$GLOBALS[
'SQ_SYSTEM']->am->assetExists($settings[
'site_assetid']))) {
72 $special_page = $state[
'asset'];
76 if ($use_direct_parent_sites == 1) {
78 $parent_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($special_page->id, SQ_LINK_TYPE_1|SQ_LINK_TYPE_2,
'site', TRUE,
'minor');
81 if (empty($parent_links)) {
86 foreach ($parent_links as $parent_link) {
87 $sites[] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parent_link[
'majorid']);
91 $sites[] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'site_assetid']);
94 $special_page_type = array_get_index($settings,
'special_page_type',
'index');
95 $override = array_get_index($settings,
'override_special_page', 0);
97 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
98 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
100 $return_array = Array();
102 foreach ($sites as $site) {
103 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($site->id, SQ_LINK_NOTICE,
'', FALSE, $special_page_type);
108 if (!$override || ($link[
'minorid'] == $special_page->id)) {
109 $return_array[] = Array(
110 'assetid' => $link[
'minorid'],
111 'site_assetid' => $site->id,
112 'special_page_type' => $special_page_type,
118 $success = (bool)$site->deleteLink($link[
'linkid']);
122 $success = (bool)$site->createLink($special_page, SQ_LINK_NOTICE, $special_page_type);
127 $return_array[] = Array(
128 'assetid' => $special_page->id,
129 'site_assetid' => $site->id,
130 'special_page_type' => $special_page_type,
137 $GLOBALS[
'SQ_SYSTEM']->doTransaction($success ?
'COMMIT' :
'ROLLBACK');
138 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
140 return ($success? $return_array : FALSE);
155 public static function getInterface($settings, $prefix, $write_access=FALSE)
157 $site_assetid = array_get_index($settings,
'site_assetid', 0);
158 $site_exists = FALSE;
160 $site_exists = $GLOBALS[
'SQ_SYSTEM']->am->assetExists($site_assetid);
163 $form_element_extras =
'';
164 if (!$write_access) {
165 $form_element_extras =
'disabled="disabled"';
170 combo_box($prefix.
'[special_page_type]', self::_getSpecialPages(), FALSE, array_get_index($settings,
'special_page_type',
'index'), NULL, $form_element_extras);
171 $special_page_selection = ob_get_clean();
176 asset_finder($prefix.
'[site_assetid]', $site_assetid, Array(
'site' =>
'I'));
180 echo get_asset_tag_line($site_assetid);
182 echo
'<span class="sq-backend-warning">Unknown asset (Id: #'.$site_assetid.
')</span>';
185 echo
'<b>No Asset ID specified</b>';
188 $site_asset_selection = ob_get_clean();
192 check_box($prefix.
'[override_special_page]',
'1', array_get_index($settings,
'override_special_page', 0), NULL, $form_element_extras);
193 label(translate(
'trigger_action_set_site_special_page_override_special_page'), $prefix.
'[override_special_page]');
194 $override_special_page_checkbox = ob_get_clean();
198 check_box($prefix.
'[use_direct_parent_sites]',
'1', array_get_index($settings,
'use_direct_parent_sites', 0), NULL, $form_element_extras);
199 label(translate(
'trigger_action_set_site_special_page_use_direct_parent_sites'), $prefix.
'[use_direct_parent_sites]');
200 $use_direct_parent_sites_checkbox = ob_get_clean();
202 $contents = translate(
'trigger_action_set_site_special_page_basic', $special_page_selection, $site_asset_selection)
204 .$override_special_page_checkbox
206 .$use_direct_parent_sites_checkbox;
227 $special_page_type = array_get_index($request_data,
'special_page_type',
'index');
228 if (!key_exists($special_page_type, self::_getSpecialPages())) {
229 return translate(
'trigger_action_set_site_special_page_special_page_type_invalid');
232 $use_direct_parent_sites = array_get_index($request_data,
'use_direct_parent_sites', 0);
234 if (($use_direct_parent_sites == 0) && empty($request_data[
'site_assetid'][
'assetid'])) {
235 return translate(
'trigger_action_set_site_special_page_site_missing');
238 $settings[
'special_page_type'] = $special_page_type;
239 $settings[
'site_assetid'] = $request_data[
'site_assetid'][
'assetid'];
240 $settings[
'override_special_page'] = array_get_index($request_data,
'override_special_page', 0);
241 $settings[
'use_direct_parent_sites'] = $use_direct_parent_sites;
256 return Array(
'index' =>
'Index',
'not_found' =>
'Not Found',
'archive' =>
'Archived Asset');