15 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
16 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
51 public static function execute($settings, &$state)
54 if (empty($state[
'asset'])) {
55 if (empty($state[
'assetid'])) {
58 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
62 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
64 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
65 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
68 $asset->_tmp[
'custom'] = TRUE;
69 $clone = $GLOBALS[
'SQ_SYSTEM']->am->cloneAsset($asset, $create_link, $map, Array(
'attributes',
'permissions',
'roles'), FALSE);
70 if (is_null($clone)) {
71 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
72 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
76 $default_name =
'Customisation #'.$clone->id;
77 $new_name = array_get_index($settings,
'customisation_name', $default_name);
79 $keywords_list = retrieve_keywords_replacements($new_name);
80 $keywords_list = array_unique($keywords_list);
81 $replacements = Array();
82 foreach ($keywords_list as $keyword) {
83 $replacements[$keyword] = $state[
'asset']->getKeywordReplacement($keyword);
85 $new_name = replace_keywords($new_name, $replacements);
88 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($clone->id,
'all')) {
89 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
90 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
97 $customisation = $clone->morph(
'design_customisation');
101 if (!$customisation) {
102 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
103 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
108 if (!$asset->createLink($customisation, SQ_LINK_TYPE_2,
'customisation', NULL,
'1')) {
109 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
110 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
113 if (!($customisation->setAttrValue(
'id_name', $new_name) && $customisation->saveAttributes())) {
114 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
115 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
119 $am = $GLOBALS[
'SQ_SYSTEM']->am;
122 $da_links = $asset->getDesignAreaLink();
123 foreach ($da_links as $link) {
124 $da = $am->getAsset($link[
'minorid'], $link[
'minor_type_code'], TRUE);
125 if (is_null($da))
continue;
126 if (!$customisation->createLink($da, SQ_LINK_TYPE_3, $link[
'value'], NULL,
'1')) {
127 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
128 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
134 $initial_path = strtolower($new_name);
135 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
136 $valid_paths = make_valid_web_paths(Array($initial_path));
137 $good_paths = $GLOBALS[
'SQ_SYSTEM']->am->webPathsInUse($asset, $valid_paths, $customisation->id, TRUE);
138 if (!$customisation->saveWebPaths($good_paths)) {
139 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
140 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
145 $file_link_ids = Array();
146 $file_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'file', FALSE);
147 foreach ($file_links as $link) {
148 $minor = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
149 if (!$customisation->createLink($minor, SQ_LINK_TYPE_3,
'', NULL, 1)) {
150 trigger_localised_error(
'CORE0162', E_USER_WARNING);
151 $am->forgetAsset($minor);
152 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
153 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
157 $am->forgetAsset($minor);
160 $css_link_ids = Array();
161 $css_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_TYPE_2 | SQ_LINK_TYPE_3,
'design_css', FALSE);
162 foreach ($css_links as $link) {
163 $minor = $am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
164 if (!$customisation->createLink($minor, SQ_LINK_TYPE_3,
'', NULL, 1)) {
165 trigger_localised_error(
'CORE0161', E_USER_WARNING);
166 $am->forgetAsset($minor);
167 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
168 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
172 $am->forgetAsset($minor);
175 if (!$GLOBALS[
'SQ_SYSTEM']->am->releaseLock($customisation->id,
'all')) {
176 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
177 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
181 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
182 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
185 'assetid' => $customisation->id,
186 'original_design' => $asset->id,
202 public static function getInterface($settings, $prefix, $write_access=FALSE)
205 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'design');
206 $tmp_design =
new Design();
207 $keywords = $tmp_design->getAvailableKeywords();
209 text_box($prefix.
'[customisation_name]',
'%asset_name% - Customisation', strlen(
'%asset_name% - Customisation'));
210 $text_box = ob_get_contents();
214 combo_box($prefix.
'[keywords]', $keywords, FALSE,
'',0,
'onchange="document.getElementById(\''.$prefix.
'[customisation_name]\').value += \' %\' + this.value + \'%\';"');
215 $combo_box = ob_get_contents();
218 $contents = translate(
'trigger_create_design_customisation_usage')
219 .
'<br /><br />'.translate(
'trigger_create_design_customisation_select_keyword').$combo_box
221 translate(
'trigger_create_design_customisation_specify_name').$text_box.
'<br />'
243 if (empty($request_data[
'customisation_name'])) {
244 return translate(
'trigger_create_design_customisation_name_missing');
247 $settings[
'customisation_name'] = $request_data[
'customisation_name'];
263 public static function getLocks($settings, &$state)
266 $state[
'assetid'] => Array(
'all'),