17 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_job.inc';
57 public static function paintConfig(&$o, $class, $write_access)
60 $o->openField(
'Hipo Job Regenerate Design');
63 text_box($class.
'[SQ_HIPO_REGENERATE_DESIGN_THRESHOLD]', SQ_HIPO_REGENERATE_DESIGN_THRESHOLD, 1);
65 echo SQ_HIPO_REGENERATE_DESIGN_THRESHOLD;
67 echo
' '.translate(
'assets');
83 'SQ_HIPO_REGENERATE_DESIGN_THRESHOLD' => Array(
'editable' => 1,
'default' => 1),
102 $code_name = parent::getCodeName();
103 return $code_name.
'-'.md5($this->_running_vars[
'assetid']);
116 return 'Hipo Job Regenerate Design';
132 'name' =>
'Hipo Job Regenerate Design',
133 'function_call' => Array(
134 'process_function' =>
'processCustomisation',
136 'running_mode' =>
'web',
138 'allow_cancel' =>
true,
159 while (!empty($this->_running_vars[
'todo_assetids'])) {
177 $parentid = isset($this->_running_vars[
'parentid']) ? $this->_running_vars[
'parentid'] : NULL;
178 $assetid = isset($this->_running_vars[
'assetid']) ? $this->_running_vars[
'assetid'] : NULL;
180 if (empty($assetid)) {
181 trigger_error(
'Unable to run HIPO job; this job requires a design asset ID', E_USER_WARNING);
184 $this->_running_vars[
'todo_assetids'] = Array();
185 $this->_running_vars[
'total_count'] = 0;
186 $all_customisations = Array();
187 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
188 $type = $asset->type();
191 if ($type ===
'design_customisation' || $type ===
'design_css_customisation') {
192 if(empty ($parentid)) {
193 trigger_error(
'To regenerate a design customisation, parentid is required', E_USER_WARNING);
196 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parentid);
197 $asset->updateFromParent($parent, FALSE);
200 $asset->generateDesignFile(FALSE);
205 $all_customisations = $this->_getCustomisations($assetid);
206 $this->_running_vars[
'total_count'] += count($all_customisations);
207 $this->_running_vars[
'todo_assetids'] = array_merge($this->_running_vars[
'todo_assetids'], $all_customisations);
208 $this->_running_vars[
'done_assetids'] = Array();
210 return parent::prepare();
226 if (!empty($this->_running_vars[
'todo_assetids'])) {
227 $current_customisation = array_shift($this->_running_vars[
'todo_assetids']);
229 $customisation = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($current_customisation[
'child']);
230 $design = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($current_customisation[
'parent']);
231 if ($acquired = $GLOBALS[
'SQ_SYSTEM']->am->acquireLock($customisation->id,
'all')) {
234 $customisation->updateFromParent($design, FALSE);
236 $this->_running_vars[
'done_assetids'][] = $current_customisation;
237 if ($acquired != 2) {
238 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($customisation->id,
'all');
245 if (empty($this->_running_vars[
'todo_assetids'])) {
246 $step_data[
'percent_done'] = 100;
247 $step_data[
'complete'] =
true;
249 $step_data[
'percent_done'] = (count($this->_running_vars[
'done_assetids']) / $this->_running_vars[
'total_count']) * 100;
250 $step_data[
'complete'] =
false;
266 private function _getCustomisations ($designid) {
267 $customisation_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($designid, SQ_LINK_TYPE_2,
'design_customisation', TRUE,
'major',
'customisation');
268 $customisation_links = array_merge($customisation_links, $GLOBALS[
'SQ_SYSTEM']->am->getLinks($designid, SQ_LINK_TYPE_2,
'design_css_customisation', TRUE,
'major',
'customisation'));
269 if (empty($customisation_links))
return Array();
271 $children_customisations = Array();
272 foreach ($customisation_links as $link) {
273 $children_customisations[] = Array(
'parent' => $designid,
'child' => $link[
'minorid']);
274 $children_customisations = array_merge($children_customisations, $this->_getCustomisations($link[
'minorid']));
276 return $children_customisations;