/** * Upgrade the Set Future Permissions and Set Future Status trigger actions * present in existing Trigger assets to the new values expected in version 0.2 * of these assets * * @param Trigger &$trigger The Trigger Asset to upgrade * * @return void * @access public */ function upgradeTrigger(Trigger &$trigger) { $trigger_actions = $trigger->attr('actions'); $trigger_modified = FALSE; foreach ($trigger_actions as $key => &$trigger_action) { $trigger_action_data =& $trigger_action['data']; // Set Future Permissions and Status triggers < v0.2 will not have an "offset_used" value if (($trigger_action['type'] == 'trigger_action_set_future_permissions' || $trigger_action['type'] == 'trigger_action_set_future_status') && !isset($trigger_action_data['offset_used'])) { // Modify data associated with the Trigger Action (using a reference for ease and fun) // Add new "offset_used" value $trigger_action_data['offset_used'] = FALSE; // Convert to new "by_attr_value" when_type and enable offset if one was specified if ($trigger_action_data['when_type'] == 'attr_interval' || $trigger_action_data['when_type'] == 'attr_exact') { $trigger_action_data['when_type'] = 'by_attr_value'; $trigger_action_data['offset_used'] = $trigger_action_data['when_type'] == 'attr_interval'; } // Convert "explicit_interval" to "explicit_exact", as the offset is now handled separately if ($trigger_action_data['when_type'] == 'explicit_interval') { $trigger_action_data['when_type'] = 'explicit_exact'; $trigger_action_data['offset_used'] = TRUE; } // Restock the main Trigger Actions array for this Trigger $trigger_actions[$key] = $trigger_action; $trigger_modified = TRUE; } } if ($trigger_modified) { // Supply the new Trigger Actions values and save the Trigger if it was modified echo "\n- Upgrading Trigger " . $trigger->id . '... '; // Ok we need the Attributes lock now... $GLOBALS['SQ_SYSTEM']->acquireLock($trigger->id, 'attributes'); $trigger->setAttrValue('actions', $trigger_actions); $trigger->saveAttributes(); $GLOBALS['SQ_SYSTEM']->releaseLock($trigger->id, 'attributes'); echo 'done'; } }