17 require_once SQ_INCLUDE_PATH.
'/asset_management.inc';
18 require_once dirname(__FILE__).
'/condition_user_ip_edit_fns.inc';
42 Asset_Management::__construct($pm);
57 if (!parent::_upgrade($current_version))
return FALSE;
59 $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(),
'name'));
61 if (version_compare($current_version,
'0.2',
'<')) {
63 pre_echo(
'STARTING UPGRADE OF '.$asset_name.
' FROM VERSION '.$current_version.
' TO VERSION 0.2');
65 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
66 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
69 $users = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'user', FALSE, TRUE);
70 pre_echo(
'Updating User restrictions - '.count($users).
' asset(s)...');
71 foreach ($users as $assetid => $type_code) {
72 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code);
73 if (is_null($asset))
continue;
75 $restrictions = $asset->attr(
'restrictions');
76 foreach ($restrictions as $group_assetid => $group_restrictions) {
77 foreach ($group_restrictions as $key => $restriction) {
81 if (!is_null($restriction)) {
82 $restrictions[$group_assetid][$key] = $restriction;
84 unset($restrictions[$group_assetid][$key]);
90 $asset->setAttrValue(
'restrictions', $restrictions);
92 if (!$asset->saveAttributes()) {
93 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
94 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
96 pre_echo($asset_name.
' UPGRADE FAILED - Could not save attributes');
100 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
106 $pl_bodycopies = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'paint_layout_bodycopy', FALSE, TRUE);
107 pre_echo(
'Updating Paint Layout Bodycopy conditions - '.count($pl_bodycopies).
' asset(s)...');
108 foreach ($pl_bodycopies as $assetid => $type_code) {
109 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code);
110 if (is_null($asset))
continue;
112 $conditional_keywords = $asset->attr(
'conditional_keywords');
113 foreach ($conditional_keywords as $condition_name => $parameters) {
114 if ($parameters[
'type_code'] == $this->
getAssetType()) {
118 $conditional_keywords[$condition_name] = $parameters;
121 $asset->setAttrValue(
'conditional_keywords', $conditional_keywords);
123 if (!$asset->saveAttributes()) {
124 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
125 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
127 pre_echo($asset_name.
' UPGRADE FAILED - Could not save attributes');
131 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
136 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
137 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
139 pre_echo($asset_name.
' SUCCESSFULLY UPGRADED TO VERSION 0.2');
158 $condition_data = $restriction[
'condition_data'];
160 if (isset($condition_data[
'user_ip'])) {
161 $ip_octets = explode(
'.', $condition_data[
'user_ip']);
162 $subnet_octets = Array(255, 255, 255, 255);
164 $non_star_found = FALSE;
167 for ($i = 3; $i >= 0; $i--) {
170 if ($ip_octets[$i] ===
'*') {
171 if ($non_star_found) {
172 trigger_error(
'Cannot upgrade IP condition "'.$condition_data[
'user_ip'].
' as it cannot be represented in a IP/subnet format - ignoring this condition', E_USER_NOTICE);
176 $subnet_octets[$i] =
'0';
177 $ip_octets[$i] =
'0';
180 $non_star_found = TRUE;
186 $match = $restriction[
'match'];
187 $condition_data[
'user_ip_ranges'] = Array(
189 'ip_address' => implode(
'.', $ip_octets),
190 'subnet' => implode(
'.', $subnet_octets),
194 $condition_data[
'default_grant'] = 1 - $match;
195 $restriction[
'match'] = TRUE;
196 unset($condition_data[
'user_ip']);
197 $restriction[
'condition_data'] = $condition_data;