public function processRecord($record) { try { $this->insertSummarizedTransaction($record); } catch(Gpf_Exception $e) { Pap3Compatibility_Migration_OutputWriter::log("<br/>Exception when inserting record ".$e->getMessage()); } }
private function deleteTable($tableName) { Pap3Compatibility_Migration_OutputWriter::logOnce(" Deleting data from table ".$tableName."....."); $sql = new Gpf_SqlBuilder_DeleteBuilder(); $sql->from->add($tableName); $sql->execute(); Pap3Compatibility_Migration_OutputWriter::log("DONE<br/>"); }
protected function migrateUsersInCampaigns() { Pap3Compatibility_Migration_OutputWriter::log(" Migrating users in campaigns....."); $selectBuilder = new Gpf_SqlBuilder_SelectBuilder(); $selectBuilder->select->add('*'); $selectBuilder->from->add('wd_pa_affiliatescampaigns'); $count = 0; foreach($selectBuilder->getAllRowsIterator() as $record) { if($record->get('affiliateid') == '' || $record->get('campcategoryid') == '') { continue; } $count++; try { $obj = new Pap_Db_UserInCommissionGroup(); $obj->setUserId($record->get('affiliateid')); $obj->setCommissionGroupId($record->get('campcategoryid')); $obj->setStatus(Pap3Compatibility_Migration_Pap3Constants::translateStatus($record->get('rstatus'))); $obj->setDateAdded(Gpf_Common_DateUtils::now()); $obj->save(); } catch(Gpf_Exception $e) { // non important error, don't display it } } Pap3Compatibility_Migration_OutputWriter::log(" ($count) ..... DONE<br/>"); }
private function deleteAffiliates() { Pap3Compatibility_Migration_OutputWriter::logOnce(" Deleting affiliates ....."); // pap users $sql = new Gpf_SqlBuilder_DeleteBuilder(); $sql->from->add(Pap_Db_Table_Users::getName()); $sql->where->add('rtype', '=', 'A'); $sql->execute(); // g_users $inSelect = new Gpf_SqlBuilder_SelectBuilder(); $inSelect->select->add(Pap_Db_Table_Users::ACCOUNTUSERID); $inSelect->from->add(Pap_Db_Table_Users::getName()); $sql = new Gpf_SqlBuilder_DeleteBuilder(); $sql->from->add(Gpf_Db_Table_Users::getName()); $sql->where->add('accountuserid', 'NOT IN', $inSelect, 'AND', false); $sql->execute(); // g_authusers $inSelect = new Gpf_SqlBuilder_SelectBuilder(); $inSelect->select->add(Gpf_Db_Table_Users::AUTHID); $inSelect->from->add(Gpf_Db_Table_Users::getName()); $sql = new Gpf_SqlBuilder_DeleteBuilder(); $sql->from->add(Gpf_Db_Table_AuthUsers::getName()); $sql->where->add('authid', 'NOT IN', $inSelect, 'AND', false); $sql->execute(); // g_userattributes $inSelect = new Gpf_SqlBuilder_SelectBuilder(); $inSelect->select->add(Gpf_Db_Table_Users::ID); $inSelect->from->add(Gpf_Db_Table_Users::getName()); $sql = new Gpf_SqlBuilder_DeleteBuilder(); $sql->from->add(Gpf_Db_Table_UserAttributes::getName()); $sql->where->add('accountuserid', 'NOT IN', $inSelect, 'AND', false); $sql->execute(); // g_gadgets $inSelect = new Gpf_SqlBuilder_SelectBuilder(); $inSelect->select->add(Gpf_Db_Table_Users::ID); $inSelect->from->add(Gpf_Db_Table_Users::getName()); $sql = new Gpf_SqlBuilder_DeleteBuilder(); $sql->from->add(Gpf_Db_Table_Gadgets::getName()); $sql->where->add('accountuserid', 'NOT IN', $inSelect, 'AND', false); $sql->execute(); Pap3Compatibility_Migration_OutputWriter::log("DONE<br/>"); }
protected function migrateBanners() { Pap3Compatibility_Migration_OutputWriter::log(" Migrating banners....."); $selectBuilder = new Gpf_SqlBuilder_SelectBuilder(); $selectBuilder->select->add('*'); $selectBuilder->from->add('wd_pa_banners', 'b'); $selectBuilder->where->add('b.deleted', '=', '0' ); $result = $selectBuilder->getAllRows(); $count = 0; foreach($result as $record) { $obj = new Pap_Common_Banner(); $obj->setId($record->get('bannerid')); $obj->setCampaignId($record->get('campaignid')); $obj->setAccountId(Pap3Compatibility_Migration_Pap3Constants::DEFAULT_ACCOUNT_ID); if($record->get('destinationurl') != '') { $obj->setDestinationUrl($record->get('destinationurl')); } else { $obj->setDestinationUrl(' '); } $obj->setName($record->get('name')); if($record->get('dateinserted') != '') { $obj->set('dateinserted', $record->get('dateinserted')); } else { $obj->set('dateinserted', Gpf_Common_DateUtils::now()); } $obj->setStatus(($record->get('hidden') == 1 ? 'H' : 'A')); $bannerType = Pap3Compatibility_Migration_Pap3Constants::translateBannerType($record->get('bannertype')); switch($bannerType) { case Pap_Common_Banner_Factory::BannerTypeText: $obj->setData1($record->get('sourceurl')); $obj->setData2($this->replaceVariables($record->get('description'))); break; case Pap_Common_Banner_Factory::BannerTypeImage: $obj->setData1($record->get('sourceurl')); break; case Pap_Common_Banner_Factory::BannerTypeHtml: $obj->setData1('N'); $obj->setData2($this->replaceVariables($record->get('description'))); break; case Pap_Common_Banner_Factory::BannerTypePopup: case Pap_Common_Banner_Factory::BannerTypePopunder: // these banners are not yet supported in PAP4 continue; case Pap_Common_Banner_Factory::BannerTypePromoEmail: $obj->setData1($record->get('sourceurl')); $obj->setData2($this->replaceVariables($record->get('description'))); break; } $obj->setBannerType($bannerType); try { $obj->save(); } catch (Gpf_Exception $e) { Pap3Compatibility_Migration_OutputWriter::log( sprintf(' Warning: banner %s not migrated. Reason: %s', $obj->getId(), $e->getMessage())); } $count++; } Pap3Compatibility_Migration_OutputWriter::log(" ($count) ..... DONE<br/>"); }
private function process() { $logName = $this->getLogName(); $taskName = str_replace(' ', '', $logName); if($this->getSkip()) { $this->logOnce(" Migrating $logName.....". "<span style=\"color:#0000ff\">SKIPPED to speed it up</span>..... DONE<br/>"); return; } else { $this->logOnce(" Migrating $logName....."); } if($this->isPending($taskName.'Start')) { $totalCount = $this->getCount(); $this->log(" Total $logName count: $totalCount, starting migration ...<br/>"); $this->setDone(); } $selectBuilder = $this->getFullSelect(); $countPreffix = $taskName.'rec_'; $progress = $this->getProgress(); if (substr($progress, 0, strlen($countPreffix)) == $countPreffix) { $count = substr($progress, strlen($countPreffix)); $selectBuilder->limit->set($count, '18446744073709551615'); } else { $count = 0; } try { $this->beforeRecordsProcessed(); foreach($selectBuilder->getAllRowsIterator() as $record) { if($this->isPending($countPreffix.$count)) { $this->processRecord($record); $this->setDone(); } $count++; } $this->afterRecordsProcessed(); } catch(Gpf_Tasks_LongTaskInterrupt $e) { $this->afterRecordsProcessed(); Pap3Compatibility_Migration_OutputWriter::log(" - completed $count records...CONTINUING<br/>"); throw $e; } $this->afterAllRecordsProcessed(); Pap3Compatibility_Migration_OutputWriter::log(" - finished $count records..... DONE<br/>"); }
/** * special handling for parent user IDs that were not set during insert * */ private function processParentUsers() { Pap3Compatibility_Migration_OutputWriter::log("<br/>Fixing parent users....."); $updateBuilder = new Gpf_SqlBuilder_UpdateBuilder(); $updateBuilder->from->add(Pap_Db_Table_Users::getName(), 'u'); $updateBuilder->from->addLeftJoin(Pap_Db_Table_Users::getName(), 'pu', 'u.parentuserid = pu.userid'); $updateBuilder->set->add('u.parentuserid' ,'NULL', false); $updateBuilder->where->add('u.parentuserid', 'is not', 'NULL', 'AND', false); $updateBuilder->where->add('pu.userid', 'is', 'NULL', 'AND', false); try { $statement = $updateBuilder->execute(); } catch (Gpf_Exception $e) { Pap3Compatibility_Migration_OutputWriter::log("<br/> Exception when updating parentuserids: ".$e->getMessage()); return; } Pap3Compatibility_Migration_OutputWriter::log("<br/> ".$statement->affectedRows()." parentuserids fixed"); }