PageRenderTime 8ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/etc/changes/migration_tables_core_327.php

https://bitbucket.org/valmy/openx
PHP | 396 lines | 306 code | 57 blank | 33 comment | 17 complexity | 01d9689eaaa54a29b1a651610e5a4aa2 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. class Migration_327 extends Migration
  28. {
  29. function Migration_327()
  30. {
  31. //$this->__construct();
  32. $this->aTaskList_constructive[] = 'beforeAddField__zones__category';
  33. $this->aTaskList_constructive[] = 'afterAddField__zones__category';
  34. $this->aTaskList_constructive[] = 'beforeAddField__zones__ad_selection';
  35. $this->aTaskList_constructive[] = 'afterAddField__zones__ad_selection';
  36. $this->aTaskList_constructive[] = 'beforeAddField__zones__inventory_forecast_type';
  37. $this->aTaskList_constructive[] = 'afterAddField__zones__inventory_forecast_type';
  38. $this->aTaskList_constructive[] = 'beforeAddField__zones__comments';
  39. $this->aTaskList_constructive[] = 'afterAddField__zones__comments';
  40. $this->aTaskList_constructive[] = 'beforeAddField__zones__cost';
  41. $this->aTaskList_constructive[] = 'afterAddField__zones__cost';
  42. $this->aTaskList_constructive[] = 'beforeAddField__zones__cost_type';
  43. $this->aTaskList_constructive[] = 'afterAddField__zones__cost_type';
  44. $this->aTaskList_constructive[] = 'beforeAddField__zones__cost_variable_id';
  45. $this->aTaskList_constructive[] = 'afterAddField__zones__cost_variable_id';
  46. $this->aTaskList_constructive[] = 'beforeAddField__zones__technology_cost';
  47. $this->aTaskList_constructive[] = 'afterAddField__zones__technology_cost';
  48. $this->aTaskList_constructive[] = 'beforeAddField__zones__technology_cost_type';
  49. $this->aTaskList_constructive[] = 'afterAddField__zones__technology_cost_type';
  50. $this->aTaskList_constructive[] = 'beforeAddField__zones__updated';
  51. $this->aTaskList_constructive[] = 'afterAddField__zones__updated';
  52. $this->aTaskList_constructive[] = 'beforeAddField__zones__block';
  53. $this->aTaskList_constructive[] = 'afterAddField__zones__block';
  54. $this->aTaskList_constructive[] = 'beforeAddField__zones__capping';
  55. $this->aTaskList_constructive[] = 'afterAddField__zones__capping';
  56. $this->aTaskList_constructive[] = 'beforeAddField__zones__session_capping';
  57. $this->aTaskList_constructive[] = 'afterAddField__zones__session_capping';
  58. $this->aObjectMap['zones']['category'] = array('fromTable'=>'zones', 'fromField'=>'category');
  59. $this->aObjectMap['zones']['ad_selection'] = array('fromTable'=>'zones', 'fromField'=>'ad_selection');
  60. $this->aObjectMap['zones']['inventory_forecast_type'] = array('fromTable'=>'zones', 'fromField'=>'inventory_forecast_type');
  61. $this->aObjectMap['zones']['comments'] = array('fromTable'=>'zones', 'fromField'=>'comments');
  62. $this->aObjectMap['zones']['cost'] = array('fromTable'=>'zones', 'fromField'=>'cost');
  63. $this->aObjectMap['zones']['cost_type'] = array('fromTable'=>'zones', 'fromField'=>'cost_type');
  64. $this->aObjectMap['zones']['cost_variable_id'] = array('fromTable'=>'zones', 'fromField'=>'cost_variable_id');
  65. $this->aObjectMap['zones']['technology_cost'] = array('fromTable'=>'zones', 'fromField'=>'technology_cost');
  66. $this->aObjectMap['zones']['technology_cost_type'] = array('fromTable'=>'zones', 'fromField'=>'technology_cost_type');
  67. $this->aObjectMap['zones']['updated'] = array('fromTable'=>'zones', 'fromField'=>'updated');
  68. $this->aObjectMap['zones']['block'] = array('fromTable'=>'zones', 'fromField'=>'block');
  69. $this->aObjectMap['zones']['capping'] = array('fromTable'=>'zones', 'fromField'=>'capping');
  70. $this->aObjectMap['zones']['session_capping'] = array('fromTable'=>'zones', 'fromField'=>'session_capping');
  71. }
  72. function beforeAddField__zones__category()
  73. {
  74. return $this->beforeAddField('zones', 'category');
  75. }
  76. function afterAddField__zones__category()
  77. {
  78. return $this->afterAddField('zones', 'category');
  79. }
  80. function beforeAddField__zones__ad_selection()
  81. {
  82. return $this->beforeAddField('zones', 'ad_selection');
  83. }
  84. function afterAddField__zones__ad_selection()
  85. {
  86. return $this->afterAddField('zones', 'ad_selection');
  87. }
  88. function beforeAddField__zones__inventory_forecast_type()
  89. {
  90. return $this->beforeAddField('zones', 'inventory_forecast_type');
  91. }
  92. function afterAddField__zones__inventory_forecast_type()
  93. {
  94. return $this->afterAddField('zones', 'inventory_forecast_type');
  95. }
  96. function beforeAddField__zones__comments()
  97. {
  98. return $this->beforeAddField('zones', 'comments');
  99. }
  100. function afterAddField__zones__comments()
  101. {
  102. return $this->afterAddField('zones', 'comments');
  103. }
  104. function beforeAddField__zones__cost()
  105. {
  106. return $this->beforeAddField('zones', 'cost');
  107. }
  108. function afterAddField__zones__cost()
  109. {
  110. return $this->afterAddField('zones', 'cost');
  111. }
  112. function beforeAddField__zones__cost_type()
  113. {
  114. return $this->beforeAddField('zones', 'cost_type');
  115. }
  116. function afterAddField__zones__cost_type()
  117. {
  118. return $this->afterAddField('zones', 'cost_type');
  119. }
  120. function beforeAddField__zones__cost_variable_id()
  121. {
  122. return $this->beforeAddField('zones', 'cost_variable_id');
  123. }
  124. function afterAddField__zones__cost_variable_id()
  125. {
  126. return $this->afterAddField('zones', 'cost_variable_id');
  127. }
  128. function beforeAddField__zones__technology_cost()
  129. {
  130. return $this->beforeAddField('zones', 'technology_cost');
  131. }
  132. function afterAddField__zones__technology_cost()
  133. {
  134. return $this->afterAddField('zones', 'technology_cost');
  135. }
  136. function beforeAddField__zones__technology_cost_type()
  137. {
  138. return $this->beforeAddField('zones', 'technology_cost_type');
  139. }
  140. function afterAddField__zones__technology_cost_type()
  141. {
  142. return $this->afterAddField('zones', 'technology_cost_type');
  143. }
  144. function beforeAddField__zones__updated()
  145. {
  146. return $this->beforeAddField('zones', 'updated');
  147. }
  148. function afterAddField__zones__updated()
  149. {
  150. return $this->afterAddField('zones', 'updated');
  151. }
  152. function beforeAddField__zones__block()
  153. {
  154. return $this->beforeAddField('zones', 'block');
  155. }
  156. function afterAddField__zones__block()
  157. {
  158. return $this->afterAddField('zones', 'block');
  159. }
  160. function beforeAddField__zones__capping()
  161. {
  162. return $this->beforeAddField('zones', 'capping');
  163. }
  164. function afterAddField__zones__capping()
  165. {
  166. return $this->afterAddField('zones', 'capping');
  167. }
  168. function beforeAddField__zones__session_capping()
  169. {
  170. return $this->beforeAddField('zones', 'session_capping');
  171. }
  172. function afterAddField__zones__session_capping()
  173. {
  174. return $this->afterAddField('zones', 'session_capping') && $this->migrateData();
  175. }
  176. function migrateData()
  177. {
  178. $prefix = $this->getPrefix();
  179. $query = "SELECT * FROM {$prefix}zones";
  180. $rsZones = DBC::NewRecordSet($query);
  181. $result = $rsZones->find();
  182. if (PEAR::isError($result)) {
  183. return $this->_logErrorAndReturnFalse('Error migrating Zones data during migration 327: '.$result->getUserInfo());
  184. }
  185. $aZoneAdObjectHandlers = array();
  186. while($result = $rsZones->fetch()) {
  187. if (PEAR::isError($result)) {
  188. return $this->_logErrorAndReturnFalse('Error migrating Zones data during migration 327: '.$result->getUserInfo());
  189. }
  190. $zonetype = $rsZones->get('zonetype');
  191. $what = $rsZones->get('what');
  192. $zoneid = $rsZones->get('zoneid');
  193. $zoneAdObjectHandler = OA_upgrade_getZoneAdObjectHandler($prefix, $zonetype, $zoneid, $what);
  194. if (!$zoneAdObjectHandler) {
  195. // Either zonetype 2 - keywords, which shouldn't be modified
  196. // or unknown / unused zone type.
  197. continue;
  198. }
  199. $aZoneAdObjectHandlers []= $zoneAdObjectHandler;
  200. }
  201. foreach ($aZoneAdObjectHandlers as $zoneAdObjectHandler) {
  202. $result = $zoneAdObjectHandler->insertAssocs($this->oDBH);
  203. if (PEAR::isError($result)) {
  204. return $this->_logErrorAndReturnFalse('Error migrating Zones data during migration 327: '.$result->getUserInfo());
  205. }
  206. if (is_array($result))
  207. {
  208. foreach ($result as $k => $v)
  209. {
  210. $this->_log($v);
  211. }
  212. }
  213. }
  214. $tableAdZoneAssoc = "{$prefix}ad_zone_assoc";
  215. $tablePlacementZoneAssoc = "{$prefix}placement_zone_assoc";
  216. $tableBanners = "{$prefix}banners";
  217. $tableZones = "{$prefix}zones";
  218. $sql = "
  219. INSERT INTO $tableAdZoneAssoc (zone_id, ad_id)
  220. SELECT zoneid, bannerid
  221. FROM $tableBanners b, $tableZones z, $tablePlacementZoneAssoc
  222. WHERE campaignid = placement_id
  223. AND zoneid = zone_id
  224. AND ((delivery = 3 AND storagetype = 'txt')
  225. OR (delivery <> 3 AND storagetype <> 'txt'
  226. AND (z.height < 0 OR z.height = b.height)
  227. AND (z.width < 0 OR z.width = b.width)))";
  228. $result = $this->oDBH->exec($sql);
  229. if (PEAR::isError($result)) {
  230. return $this->_logErrorAndReturnFalse('Error inserting AdZoneAssoc data during migration 327: '.$result->getUserInfo());
  231. }
  232. $sql = "INSERT INTO $tableAdZoneAssoc (zone_id, ad_id, link_type)
  233. SELECT 0 zone_id, bannerid ad_id, 0 link_type FROM $tableBanners";
  234. $result = $this->oDBH->exec($sql);
  235. if (PEAR::isError($result)) {
  236. return $this->_logErrorAndReturnFalse('Error inserting AdZoneAssoc data during migration 327: '.$result->getUserInfo());
  237. }
  238. return true;
  239. }
  240. }
  241. function OA_upgrade_getAdObjectIds($sIdList, $adObjectType)
  242. {
  243. if (empty($sIdList)) {
  244. return array();
  245. }
  246. $aAdObjectIdsHolders = explode(",", $sIdList);
  247. $aIds = array();
  248. $idxStart = strlen($adObjectType) + 1;
  249. foreach ($aAdObjectIdsHolders as $idHolder) {
  250. $id = substr($idHolder, $idxStart);
  251. $aIds []= $id;
  252. }
  253. return $aIds;
  254. }
  255. function OA_upgrade_getZoneAdObjectHandler($prefix, $zonetype, $zone_id, $sIdList)
  256. {
  257. if ($zonetype == 0) {
  258. return new ZoneBannerHandler($prefix, $zone_id, $sIdList);
  259. }
  260. else if ($zonetype == 3) {
  261. return new ZoneCampaignHandler($prefix, $zone_id, $sIdList);
  262. }
  263. else {
  264. return false; // Unknown / unused zone type
  265. }
  266. }
  267. class ZoneAdObjectHandler
  268. {
  269. var $zone_id;
  270. var $aAdObjectIds;
  271. var $prefix;
  272. function ZoneAdObjectHandler($prefix, $zone_id, $sIdList, $adObjectType)
  273. {
  274. $this->zone_id = $zone_id;
  275. $this->aAdObjectIds = OA_upgrade_getAdObjectIds($sIdList, $adObjectType);
  276. $this->prefix = $prefix;
  277. }
  278. /**
  279. * Inserts associations between zone and ad objects (campaign or banner)
  280. * represented by this handler.
  281. *
  282. * @param MDB2_Driver_Common $oDbh
  283. */
  284. function insertAssocs($oDbh)
  285. {
  286. $assocTable = $this->getAssocTable();
  287. $adObjectColumn = $this->getAdObjectColumn();
  288. $result = true;
  289. foreach($this->aAdObjectIds as $adObjectId) {
  290. $sql = "
  291. INSERT INTO {$this->prefix}$assocTable (zone_id, $adObjectColumn)
  292. VALUES ({$this->zone_id}, $adObjectId)";
  293. if (is_numeric($adObjectId))
  294. {
  295. $result = $oDbh->exec($sql);
  296. if (PEAR::isError($result)) {
  297. return $result;
  298. }
  299. }
  300. else
  301. {
  302. $aResult[] = 'Invalid data found during migration_tables_core_127: '.$sql;
  303. }
  304. $result = $aResult;
  305. }
  306. return true;
  307. }
  308. }
  309. class ZoneBannerHandler extends ZoneAdObjectHandler
  310. {
  311. function ZoneBannerHandler($prefix, $zone_id, $sIdList)
  312. {
  313. $this->ZoneAdObjectHandler($prefix, $zone_id, $sIdList, 'bannerid');
  314. }
  315. function getAssocTable()
  316. {
  317. return 'ad_zone_assoc';
  318. }
  319. function getAdObjectColumn()
  320. {
  321. return 'ad_id';
  322. }
  323. }
  324. class ZoneCampaignHandler extends ZoneAdObjectHandler
  325. {
  326. function ZoneCampaignHandler($prefix, $zone_id, $sIdList)
  327. {
  328. $this->ZoneAdObjectHandler($prefix, $zone_id, $sIdList, 'campaignid');
  329. }
  330. function getAssocTable()
  331. {
  332. return 'placement_zone_assoc';
  333. }
  334. function getAdObjectColumn()
  335. {
  336. return 'placement_id';
  337. }
  338. }
  339. ?>