示例#1
0
    public static function getCleanMobileNumberIncDups($queue_id)
    {
        $queue_id = intval($queue_id);
        $criteriaWhiteList = new CDbCriteria();
        $criteriaWhiteList->compare("queue_id", $queue_id);
        $totalWhiteListed = WhiteListedMobile::model()->count($criteriaWhiteList);
        $totalWhiteListed = intval($totalWhiteListed);
        /*get total white list using queue id*/
        $offset = 0;
        $limit = 1000000;
        do {
            $sqlQuery = '
select a.mobile_number
from white_listed_mobile as a
left join black_listed_mobile as b on a.mobile_number = b.mobile_number
where
a.queue_id = ' . $queue_id . ' and
b.mobile_number IS NULL
LIMIT ' . $limit . '
OFFSET ' . $offset . '
            ';
            $allResults = Yii::app()->db->createCommand($sqlQuery)->queryAll();
            foreach ($allResults as $curVal) {
                echo $curVal['mobile_number'] . "\r\n";
            }
            $offset += $limit;
        } while ($offset < $totalWhiteListed);
    }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return WhiteListedMobile the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = WhiteListedMobile::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionIndex()
 {
     Yii::import("application.models.*");
     //get a queued file
     $criteria = new CDbCriteria();
     $criteria->addInCondition("status", array("IDLE", "REQUEUE"));
     /* @var $currentQueue WhitelistJobQueue*/
     $currentQueue = WhitelistJobQueue::model()->find($criteria);
     //if no queued file die()
     if (!$currentQueue) {
         echo "No files in queue";
         die;
     }
     // else continue as usuall
     $currentQueue->status = WhitelistJobQueue::$JOBQUEUE_STATUS_ON_GOING;
     $currentQueue->save(false);
     //get contents
     $currentCsvFile = new SplFileObject($currentQueue->filename);
     $currentCsvFile->setFlags(SplFileObject::READ_CSV | SplFileObject::READ_AHEAD | SplFileObject::DROP_NEW_LINE | SplFileObject::SKIP_EMPTY);
     //get total number of lines
     $currentCsvFile->seek(PHP_INT_MAX);
     $linesTotal = $currentCsvFile->key();
     $currentQueue->total_records = $linesTotal;
     $currentQueue->save(false);
     $currentCsvFile->rewind();
     $currentCsvFile->next();
     //foreach content , lookup in the blacklist record
     $index = 0;
     foreach ($currentCsvFile as $content) {
         if ($currentCsvFile->key() === 0) {
             continue;
         }
         $currentQueue->processed_record = ++$index;
         $currentQueue->save(false);
         $currentMobileNumber = $content[0];
         $curMobileObj = new WhiteListedMobile();
         //cleaning time
         $currentMobileNumber = trim($currentMobileNumber);
         $currentMobileNumber = rtrim($currentMobileNumber);
         $currentMobileNumber = ltrim($currentMobileNumber);
         $curMobileObj->mobile_number = $currentMobileNumber;
         $curMobileObj->queue_id = $currentQueue->queue_id;
         $criteria2 = new CDbCriteria();
         $criteria2->addSearchCondition("mobile_number", $currentMobileNumber);
         $isOpted = BlackListedMobile::model()->exists($criteria2);
         //if opted , set status error
         if ($isOpted) {
             $curMobileObj->status = WhiteListedMobile::$WHITELISTEDMOBILE_STATUS_ERROR;
         } else {
             //else status ok
             $curMobileObj->status = WhiteListedMobile::$WHITELISTEDMOBILE_STATUS_OK;
         }
         $curMobileObj->save();
         echo "{$curMobileObj->mobile_number}  : {$curMobileObj->status} \n";
     }
     //done
     $currentQueue->status = WhitelistJobQueue::$JOBQUEUE_STATUS_DONE;
     $currentQueue->date_done = date("Y-m-d H:i:s");
     //set done datetime to now()
     $currentQueue->save();
 }