PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/etc/changes/migration_tables_core_127.php

https://bitbucket.org/valmy/openx
PHP | 405 lines | 312 code | 60 blank | 33 comment | 17 complexity | 3c6163f5f44e1cdb54a9f6c8aca430d1 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id$
  25. */
  26. require_once(MAX_PATH.'/lib/OA/Upgrade/Migration.php');
  27. require_once(MAX_PATH.'/lib/max/other/common.php');
  28. class Migration_127 extends Migration
  29. {
  30. function Migration_127()
  31. {
  32. //$this->__construct();
  33. $this->aTaskList_constructive[] = 'beforeAddField__zones__category';
  34. $this->aTaskList_constructive[] = 'afterAddField__zones__category';
  35. $this->aTaskList_constructive[] = 'beforeAddField__zones__ad_selection';
  36. $this->aTaskList_constructive[] = 'afterAddField__zones__ad_selection';
  37. $this->aTaskList_constructive[] = 'beforeAddField__zones__forceappend';
  38. $this->aTaskList_constructive[] = 'afterAddField__zones__forceappend';
  39. $this->aTaskList_constructive[] = 'beforeAddField__zones__inventory_forecast_type';
  40. $this->aTaskList_constructive[] = 'afterAddField__zones__inventory_forecast_type';
  41. $this->aTaskList_constructive[] = 'beforeAddField__zones__comments';
  42. $this->aTaskList_constructive[] = 'afterAddField__zones__comments';
  43. $this->aTaskList_constructive[] = 'beforeAddField__zones__cost';
  44. $this->aTaskList_constructive[] = 'afterAddField__zones__cost';
  45. $this->aTaskList_constructive[] = 'beforeAddField__zones__cost_type';
  46. $this->aTaskList_constructive[] = 'afterAddField__zones__cost_type';
  47. $this->aTaskList_constructive[] = 'beforeAddField__zones__cost_variable_id';
  48. $this->aTaskList_constructive[] = 'afterAddField__zones__cost_variable_id';
  49. $this->aTaskList_constructive[] = 'beforeAddField__zones__technology_cost';
  50. $this->aTaskList_constructive[] = 'afterAddField__zones__technology_cost';
  51. $this->aTaskList_constructive[] = 'beforeAddField__zones__technology_cost_type';
  52. $this->aTaskList_constructive[] = 'afterAddField__zones__technology_cost_type';
  53. $this->aTaskList_constructive[] = 'beforeAddField__zones__updated';
  54. $this->aTaskList_constructive[] = 'afterAddField__zones__updated';
  55. $this->aTaskList_constructive[] = 'beforeAddField__zones__block';
  56. $this->aTaskList_constructive[] = 'afterAddField__zones__block';
  57. $this->aTaskList_constructive[] = 'beforeAddField__zones__capping';
  58. $this->aTaskList_constructive[] = 'afterAddField__zones__capping';
  59. $this->aTaskList_constructive[] = 'beforeAddField__zones__session_capping';
  60. $this->aTaskList_constructive[] = 'afterAddField__zones__session_capping';
  61. $this->aObjectMap['zones']['category'] = array('fromTable'=>'zones', 'fromField'=>'category');
  62. $this->aObjectMap['zones']['ad_selection'] = array('fromTable'=>'zones', 'fromField'=>'ad_selection');
  63. $this->aObjectMap['zones']['forceappend'] = array('fromTable'=>'zones', 'fromField'=>'forceappend');
  64. $this->aObjectMap['zones']['inventory_forecast_type'] = array('fromTable'=>'zones', 'fromField'=>'inventory_forecast_type');
  65. $this->aObjectMap['zones']['comments'] = array('fromTable'=>'zones', 'fromField'=>'comments');
  66. $this->aObjectMap['zones']['cost'] = array('fromTable'=>'zones', 'fromField'=>'cost');
  67. $this->aObjectMap['zones']['cost_type'] = array('fromTable'=>'zones', 'fromField'=>'cost_type');
  68. $this->aObjectMap['zones']['cost_variable_id'] = array('fromTable'=>'zones', 'fromField'=>'cost_variable_id');
  69. $this->aObjectMap['zones']['technology_cost'] = array('fromTable'=>'zones', 'fromField'=>'technology_cost');
  70. $this->aObjectMap['zones']['technology_cost_type'] = array('fromTable'=>'zones', 'fromField'=>'technology_cost_type');
  71. $this->aObjectMap['zones']['updated'] = array('fromTable'=>'zones', 'fromField'=>'updated');
  72. $this->aObjectMap['zones']['block'] = array('fromTable'=>'zones', 'fromField'=>'block');
  73. $this->aObjectMap['zones']['capping'] = array('fromTable'=>'zones', 'fromField'=>'capping');
  74. $this->aObjectMap['zones']['session_capping'] = array('fromTable'=>'zones', 'fromField'=>'session_capping');
  75. }
  76. function beforeAddField__zones__category()
  77. {
  78. return $this->beforeAddField('zones', 'category');
  79. }
  80. function afterAddField__zones__category()
  81. {
  82. return $this->afterAddField('zones', 'category');
  83. }
  84. function beforeAddField__zones__ad_selection()
  85. {
  86. return $this->beforeAddField('zones', 'ad_selection');
  87. }
  88. function afterAddField__zones__ad_selection()
  89. {
  90. return $this->afterAddField('zones', 'ad_selection');
  91. }
  92. function beforeAddField__zones__forceappend()
  93. {
  94. return $this->beforeAddField('zones', 'forceappend');
  95. }
  96. function afterAddField__zones__forceappend()
  97. {
  98. return $this->afterAddField('zones', 'forceappend');
  99. }
  100. function beforeAddField__zones__inventory_forecast_type()
  101. {
  102. return $this->beforeAddField('zones', 'inventory_forecast_type');
  103. }
  104. function afterAddField__zones__inventory_forecast_type()
  105. {
  106. return $this->afterAddField('zones', 'inventory_forecast_type');
  107. }
  108. function beforeAddField__zones__comments()
  109. {
  110. return $this->beforeAddField('zones', 'comments');
  111. }
  112. function afterAddField__zones__comments()
  113. {
  114. return $this->afterAddField('zones', 'comments');
  115. }
  116. function beforeAddField__zones__cost()
  117. {
  118. return $this->beforeAddField('zones', 'cost');
  119. }
  120. function afterAddField__zones__cost()
  121. {
  122. return $this->afterAddField('zones', 'cost');
  123. }
  124. function beforeAddField__zones__cost_type()
  125. {
  126. return $this->beforeAddField('zones', 'cost_type');
  127. }
  128. function afterAddField__zones__cost_type()
  129. {
  130. return $this->afterAddField('zones', 'cost_type');
  131. }
  132. function beforeAddField__zones__cost_variable_id()
  133. {
  134. return $this->beforeAddField('zones', 'cost_variable_id');
  135. }
  136. function afterAddField__zones__cost_variable_id()
  137. {
  138. return $this->afterAddField('zones', 'cost_variable_id');
  139. }
  140. function beforeAddField__zones__technology_cost()
  141. {
  142. return $this->beforeAddField('zones', 'technology_cost');
  143. }
  144. function afterAddField__zones__technology_cost()
  145. {
  146. return $this->afterAddField('zones', 'technology_cost');
  147. }
  148. function beforeAddField__zones__technology_cost_type()
  149. {
  150. return $this->beforeAddField('zones', 'technology_cost_type');
  151. }
  152. function afterAddField__zones__technology_cost_type()
  153. {
  154. return $this->afterAddField('zones', 'technology_cost_type');
  155. }
  156. function beforeAddField__zones__updated()
  157. {
  158. return $this->beforeAddField('zones', 'updated');
  159. }
  160. function afterAddField__zones__updated()
  161. {
  162. return $this->afterAddField('zones', 'updated');
  163. }
  164. function beforeAddField__zones__block()
  165. {
  166. return $this->beforeAddField('zones', 'block');
  167. }
  168. function afterAddField__zones__block()
  169. {
  170. return $this->afterAddField('zones', 'block');
  171. }
  172. function beforeAddField__zones__capping()
  173. {
  174. return $this->beforeAddField('zones', 'capping');
  175. }
  176. function afterAddField__zones__capping()
  177. {
  178. return $this->afterAddField('zones', 'capping');
  179. }
  180. function beforeAddField__zones__session_capping()
  181. {
  182. return $this->beforeAddField('zones', 'session_capping');
  183. }
  184. function afterAddField__zones__session_capping()
  185. {
  186. return $this->afterAddField('zones', 'session_capping') && $this->migrateData();
  187. }
  188. function migrateData()
  189. {
  190. $prefix = $this->getPrefix();
  191. $table = $this->oDBH->quoteIdentifier($prefix.'zones',true);
  192. $query = "SELECT * FROM {$table}";
  193. $rsZones = DBC::NewRecordSet($query);
  194. $result = $rsZones->find();
  195. if (PEAR::isError($result)) {
  196. return $this->_logErrorAndReturnFalse('Error migrating Zone data during migration 127: '.$result->getUserInfo());
  197. }
  198. $aZoneAdObjectHandlers = array();
  199. while($result = $rsZones->fetch()) {
  200. if (PEAR::isError($result)) {
  201. return $this->_logErrorAndReturnFalse('Error migrating Zones data during migration 127: '.$result->getUserInfo());
  202. }
  203. $zonetype = $rsZones->get('zonetype');
  204. $what = $rsZones->get('what');
  205. $zoneid = $rsZones->get('zoneid');
  206. $zoneAdObjectHandler = OA_upgrade_getZoneAdObjectHandler($prefix, $zonetype, $zoneid, $what);
  207. if (!$zoneAdObjectHandler) {
  208. // Either zonetype 2 - keywords, which shouldn't be modified
  209. // or unknown / unused zone type.
  210. continue;
  211. }
  212. $aZoneAdObjectHandlers []= $zoneAdObjectHandler;
  213. }
  214. foreach ($aZoneAdObjectHandlers as $zoneAdObjectHandler) {
  215. $result = $zoneAdObjectHandler->insertAssocs($this->oDBH);
  216. if (PEAR::isError($result)) {
  217. return $this->_logErrorAndReturnFalse('Error migrating Zones data during migration 127: '.$result->getUserInfo());
  218. } elseif (is_array($result)) {
  219. foreach ($result as $error) {
  220. $this->_logError($error);
  221. }
  222. }
  223. }
  224. $tableAdZoneAssoc = $this->oDBH->quoteIdentifier($prefix.'ad_zone_assoc',true);
  225. $tablePlacementZoneAssoc = $this->oDBH->quoteIdentifier($prefix.'placement_zone_assoc',true);
  226. $tableBanners = $this->oDBH->quoteIdentifier($prefix.'banners',true);
  227. $tableZones = $this->oDBH->quoteIdentifier($prefix.'zones',true);
  228. $sql = "
  229. INSERT INTO $tableAdZoneAssoc (zone_id, ad_id)
  230. SELECT zoneid, bannerid
  231. FROM $tableBanners b, $tableZones z, $tablePlacementZoneAssoc
  232. WHERE campaignid = placement_id
  233. AND zoneid = zone_id
  234. AND ((delivery = 3 AND storagetype = 'txt')
  235. OR (delivery <> 3 AND storagetype <> 'txt'
  236. AND (z.height < 0 OR z.height = b.height)
  237. AND (z.width < 0 OR z.width = b.width)))";
  238. $result = $this->oDBH->exec($sql);
  239. if (PEAR::isError($result)) {
  240. return $this->_logErrorAndReturnFalse('Error migrating Zones data during migration 127: '.$result->getUserInfo());
  241. }
  242. $sql = "INSERT INTO $tableAdZoneAssoc (zone_id, ad_id, link_type)
  243. SELECT 0 AS zone_id, bannerid AS ad_id, 0 AS link_type FROM $tableBanners";
  244. $result = $this->oDBH->exec($sql);
  245. if (PEAR::isError($result)) {
  246. return $this->_logErrorAndReturnFalse('Error migrating Zones data during migration 127: '.$result->getUserInfo());
  247. }
  248. return true;
  249. }
  250. }
  251. function OA_upgrade_getAdObjectIds($sIdList, $adObjectType)
  252. {
  253. if (empty($sIdList)) {
  254. return array();
  255. }
  256. $aAdObjectIdsHolders = explode(",", $sIdList);
  257. $aIds = array();
  258. $idxStart = strlen($adObjectType) + 1;
  259. foreach ($aAdObjectIdsHolders as $idHolder) {
  260. $id = substr($idHolder, $idxStart);
  261. $aIds []= $id;
  262. }
  263. return $aIds;
  264. }
  265. function OA_upgrade_getZoneAdObjectHandler($prefix, $zonetype, $zone_id, $sIdList)
  266. {
  267. if ($zonetype == 0) {
  268. return new ZoneBannerHandler($prefix, $zone_id, $sIdList);
  269. }
  270. else if ($zonetype == 3) {
  271. return new ZoneCampaignHandler($prefix, $zone_id, $sIdList);
  272. }
  273. else {
  274. return false; // Unknown / unused zone type
  275. }
  276. }
  277. class ZoneAdObjectHandler
  278. {
  279. var $zone_id;
  280. var $aAdObjectIds;
  281. var $prefix;
  282. function ZoneAdObjectHandler($prefix, $zone_id, $sIdList, $adObjectType)
  283. {
  284. $this->zone_id = $zone_id;
  285. $this->aAdObjectIds = OA_upgrade_getAdObjectIds($sIdList, $adObjectType);
  286. $this->prefix = $prefix;
  287. }
  288. /**
  289. * Inserts associations between zone and ad objects (campaign or banner)
  290. * represented by this handler.
  291. *
  292. * @param MDB2_Driver_Common $oDbh
  293. */
  294. function insertAssocs($oDbh)
  295. {
  296. $assocTable = $oDbh->quoteIdentifier($this->prefix.$this->getAssocTable(),true);
  297. $adObjectColumn = $this->getAdObjectColumn();
  298. $aResult = array();
  299. foreach($this->aAdObjectIds as $adObjectId) {
  300. if (is_numeric($adObjectId)) {
  301. $sql = "
  302. INSERT INTO {$assocTable} (zone_id, $adObjectColumn)
  303. VALUES ({$this->zone_id}, $adObjectId)";
  304. $result = $oDbh->exec($sql);
  305. if (PEAR::isError($result)) {
  306. return $result;
  307. }
  308. } else {
  309. $aResult[] = 'Invalid data found during migration_tables_core_127: '.$sql;
  310. }
  311. }
  312. return count($aResult) ? $aResult : true;
  313. }
  314. }
  315. class ZoneBannerHandler extends ZoneAdObjectHandler
  316. {
  317. function ZoneBannerHandler($prefix, $zone_id, $sIdList)
  318. {
  319. $this->ZoneAdObjectHandler($prefix, $zone_id, $sIdList, 'bannerid');
  320. }
  321. function getAssocTable()
  322. {
  323. return 'ad_zone_assoc';
  324. }
  325. function getAdObjectColumn()
  326. {
  327. return 'ad_id';
  328. }
  329. }
  330. class ZoneCampaignHandler extends ZoneAdObjectHandler
  331. {
  332. function ZoneCampaignHandler($prefix, $zone_id, $sIdList)
  333. {
  334. $this->ZoneAdObjectHandler($prefix, $zone_id, $sIdList, 'clientid');
  335. }
  336. function getAssocTable()
  337. {
  338. return 'placement_zone_assoc';
  339. }
  340. function getAdObjectColumn()
  341. {
  342. return 'placement_id';
  343. }
  344. }
  345. ?>