public function actionIndex()
 {
     Yii::import("application.models.*");
     //get the latest idle cron job
     /* @var $latestidle JobQueue*/
     $latestidle = JobQueue::model()->findByAttributes(array("status" => JobQueue::$JOBQUEUE_STATUS_IDLE));
     if (!$latestidle) {
         echo "No file queued";
         die;
     }
     //set status to on-going
     $latestidle->status = JobQueue::$JOBQUEUE_STATUS_ON_GOING;
     $latestidle->save(false);
     //retrieve file
     $queueFile = new SplFileObject($latestidle->filename);
     //read file
     $queueFile->setFlags(SplFileObject::READ_CSV | SplFileObject::READ_AHEAD | SplFileObject::DROP_NEW_LINE | SplFileObject::SKIP_EMPTY);
     $queueFile->next();
     // Total_records ,
     $queueFile->seek(PHP_INT_MAX);
     $linesTotal = $queueFile->key();
     $latestidle->total_records = $linesTotal;
     $latestidle->save(false);
     $index = 0;
     foreach ($queueFile as $currentLine) {
         //iterate content
         if ($queueFile->key() === 0) {
             continue;
         }
         //TODO: processed_record
         $latestidle->processed_record = ++$index;
         $latestidle->save(false);
         $currentMobile = $currentLine[0];
         $newBlackListedmobile = new BlackListedMobile();
         //cleaning time
         $currentMobile = trim($currentMobile);
         $currentMobile = rtrim($currentMobile);
         $currentMobile = ltrim($currentMobile);
         $newBlackListedmobile->mobile_number = $currentMobile;
         $newBlackListedmobile->queue_id = $latestidle->queue_id;
         //set queueid
         if ($newBlackListedmobile->save()) {
             //save content
             echo "{$newBlackListedmobile->mobile_number} : Saved \n";
         } else {
             echo "{$newBlackListedmobile->mobile_number} : Failed \n";
         }
     }
     //when done
     //set status to done
     $latestidle->status = JobQueue::$JOBQUEUE_STATUS_DONE;
     $latestidle->date_done = date("Y-m-d H:i:s");
     //set done datetime to now()
     $latestidle->save();
     echo "Queue DONE \n";
 }
Ejemplo n.º 2
0
<?php

/* @var $this DefaultController */
/* @var $model JobQueue */
$model = JobQueue::model();
$model->unsetAttributes();
$this->breadcrumbs = array($this->module->id);
$this->breadcrumbs = array(ucwords($this->module->id), 'Job Queues');
/*register submit event listener*/
$registerSubmitListener = <<<EOL
jQuery("form:first").submit(function(event) {
    if (  \$("#massiveTextArea").val().length > 0 ) {
        submitPartition()
        event.preventDefault();
        return false;
    }
});
EOL;
Yii::app()->clientScript->registerScript('registerSubmitListener', $registerSubmitListener, CClientScript::POS_READY);
/*end of register submit*/
/*begin partition upload of from texterea*/
$partitionUploadCode = <<<EOL
var tempTotalInsertedContainer = 0;
var tempTotalDuplicateFound = 0;
/**
 * Todo attach this before submit . make sure to change submit text 
 * @return 
 */
function submitPartition() {
    // check if multiline has data 
    if (jQuery("#massiveTextArea").val().length > 0) {
Ejemplo n.º 3
0
?>
" >
						<i class="fa fa-eye"></i>
						View
					</a>
				</li>
			</ul>
		</div>
	</div>	
	<h5>
		<small>
		<b>Queue Name</b> <br>
		</small>
			<strong>
				<?php 
$model = JobQueue::model()->findByAttributes(array('queue_id' => $data->queue_id));
if ($model) {
    echo basename($model->queue_name);
} else {
    echo "Not Available";
}
?>
			</strong>
		<br>
		<small>
			<b>Date Uploaded</b> <br>
		</small>
			<strong>
				<?php 
echo date("jS \\of F Y h:i:s A", strtotime($data->date_created));
?>
Ejemplo n.º 4
0
 /**
  * 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 JobQueue the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = JobQueue::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Ejemplo n.º 5
0
    public function actionIndex()
    {
        $uploadedFile = CUploadedFile::getInstanceByName("blackListedFile");
        if (isset($_GET['downloadSampleFile'])) {
            $headers = array("Mobilephone");
            $contents = array(array("447123456789"), array("447123456455"), array("447123456321"));
            $tempFile = new SplTempFileObject();
            $tempFile->fputcsv($headers);
            foreach ($contents as $currentLine) {
                $tempFile->fputcsv($currentLine);
            }
            $tempFile->rewind();
            header("Content-type: text/csv");
            header("Content-Disposition: attachment; filename=SampleFile.csv");
            header("Pragma: no-cache");
            header("Expires: 0");
            $tempFile->fpassthru();
            die;
        }
        if (isset($_POST['singleBlackList']) && !empty($_POST['singleBlackList'])) {
            $newMobileNum = new BlackListedMobile();
            $newMobileNum->mobile_number = $_POST['singleBlackList'];
            $newMobileNum->queue_id = 1;
            if ($newMobileNum->save()) {
                Yii::app()->user->setFlash('success', '<strong>New blacklist mobile numberSaved!</strong>');
            } else {
                Yii::app()->user->setFlash('error', '<strong>Error!</strong>' . CHtml::errorSummary($newMobileNum));
            }
        }
        if (isset($_POST['massiveTextArea']) && !empty($_POST['massiveTextArea'])) {
            /*@TODO get total now , using randomQueue  */
            $queueName = $_POST['randomQueue'] ? $_POST['randomQueue'] : 'Task : upload - ' . rand(0, 9999);
            $criteriaJobQueue = new CDbCriteria();
            $criteriaJobQueue->compare("queue_name", $queueName);
            $jobQueueModl = JobQueue::model()->find($criteriaJobQueue);
            /*@TODO $total_before*/
            $total_before = 0;
            if (!$jobQueueModl) {
                $jobQueueModl = new JobQueue();
                //@TODO declare above ,
                $jobQueueModl->queue_name = $queueName;
                $jobQueueModl->save(false);
                //pre save
            } else {
                $criteriaTotalBefore = new CDbCriteria();
                $criteriaTotalBefore->compare("queue_id", $jobQueueModl->queue_id);
                $total_before = BlackListedMobile::model()->count($criteriaTotalBefore);
            }
            /*write posted textarea to file*/
            $tp = tempnam(Yii::getPathOfAlias('application.data'), "tempWrite");
            $tempName = $tp . '.csv';
            $linecount = 0;
            $tempContainer2 = explode("\n", $_POST['massiveTextArea']);
            $tempContainer2 = array_filter($tempContainer2);
            $linecount = count($tempContainer2);
            file_put_contents($tempName, implode(PHP_EOL, $tempContainer2));
            // $handle = fopen($tempName, "r");
            // while(!feof($handle)){
            //     $line = fgets($handle);
            //     ++$linecount;
            // }
            // fclose($handle);
            $jobQueueModl->filename = $tempName;
            //ignore this
            $jobQueueModl->status = JobQueue::$JOBQUEUE_STATUS_PRELOADED;
            /*check number files' number of line*/
            // Total_records ,
            $jobQueueModl->total_records = $linecount;
            $jobQueueModl->processed_record = $linecount;
            /*update job queue record*/
            if ($jobQueueModl->save()) {
                $filePath = $tempName;
                /*load to database*/
                $tempFile2 = tempnam(__DIR__, "tempContainer");
                $appendCommand = sprintf('cat "%s" | gawk \'{print $0",0%s"}\'  > "%s" ', $filePath, $jobQueueModl->queue_id, $tempFile2);
                system($appendCommand);
                system("mv \"{$tempFile2}\" \"{$filePath}\"");
                $sqlCommand = <<<EOL
LOAD DATA LOCAL INFILE "%s"
INTO TABLE black_listed_mobile
FIELDS TERMINATED BY "%s"
LINES TERMINATED BY "%s"
IGNORE 0 LINES
(mobile_number,queue_id)
EOL;
                $sqlCommand = sprintf($sqlCommand, $filePath, ',', '\\n');
                $mainCommand = "mysql  --user=dncsyste_dnc --password=hitman052529 --database=dncsyste_dnc -e '{$sqlCommand}'";
                exec($mainCommand);
                $criteriaTotalBefore = new CDbCriteria();
                $criteriaTotalBefore->compare("queue_id", $jobQueueModl->queue_id);
                /* $total_now*/
                $total_now = BlackListedMobile::model()->count($criteriaTotalBefore);
                if (Yii::app()->request->isAjaxRequest) {
                    header("Content-Type: application/json");
                    $numOfInsertedData = $total_now - $total_before;
                    $numOfInsertedData = $numOfInsertedData <= 0 ? 0 : $numOfInsertedData;
                    $numOfDeletedData = $linecount - ($total_now - $total_before);
                    $numOfDeletedData = $numOfDeletedData <= 0 ? 0 : $numOfDeletedData;
                    $jsonResult = array("numOfInsertedData" => $numOfInsertedData, "numOfDeletedData" => $numOfDeletedData);
                    echo json_encode($jsonResult);
                    die;
                } else {
                    Yii::app()->user->setFlash('success', '<strong>File Imported!</strong>You have successfully imported new blacklisted mobile number. ');
                }
            } else {
                Yii::app()->user->setFlash('error', CHtml::errorSummary($newQueueFile));
            }
        }
        if ($uploadedFile) {
            set_time_limit(0);
            $newFileLocation = Yii::getPathOfAlias("application.uploaded_files") . DIRECTORY_SEPARATOR . rand(0, 9999) . '-' . $uploadedFile->name;
            //save new queue file
            $newQueueFile = new JobQueue();
            $uploadedFile->saveAs($newFileLocation);
            $newQueueFile->queue_name = "Task : " . $uploadedFile->name . ' - ' . rand(0, 9999);
            $newQueueFile->filename = $newFileLocation;
            $newQueueFile->status = JobQueue::$JOBQUEUE_STATUS_PRELOADED;
            /*check number files' number of line*/
            $linesTotal = 0;
            $handle = fopen($newQueueFile->filename, "r");
            while (!feof($handle)) {
                $line = fgets($handle);
                ++$linesTotal;
            }
            fclose($handle);
            $newQueueFile->total_records = $linesTotal;
            $newQueueFile->processed_record = $linesTotal;
            if ($newQueueFile->save()) {
                $filePath = $newQueueFile->filename;
                $tempFile2 = tempnam(__DIR__, "tempContainer");
                $appendCommand = sprintf('gawk \'{print $0",0%s"}\' "%s"  > "%s"', $newQueueFile->queue_id, $filePath, $tempFile2);
                system($appendCommand);
                system("mv \"{$tempFile2}\" \"{$filePath}\"");
                /*append queue identification for blacklist*/
                $rawContents = file_get_contents($filePath);
                //		print_r( explode("\n",$rawContents)  );
                //		die();
                $sqlCommand = <<<EOL
LOAD DATA LOCAL INFILE "%s"
INTO TABLE black_listed_mobile
FIELDS TERMINATED BY "%s"
LINES TERMINATED BY "%s"
IGNORE 0 LINES
(mobile_number,queue_id)
EOL;
                $sqlCommand = sprintf($sqlCommand, $filePath, ',', '\\n');
                $mainCommand = "mysql  --user=dncsyste_dnc --password=hitman052529 --database=dncsyste_dnc -e '{$sqlCommand}'";
                exec($mainCommand);
                $undoLink = "<a href='" . Yii::app()->getBaseUrl(true) . "/blacklist/delete?queue_id={$newQueueFile->queue_id}' onClick='return confirm(\"Are you sure you want to delete this ?\")'> Undo Action  </a>";
                Yii::app()->user->setFlash('success', '<strong>File Imported!</strong>You have successfully imported new blacklisted mobile number. ' . $undoLink);
            } else {
                Yii::app()->user->setFlash('error', CHtml::errorSummary($newQueueFile));
            }
        }
        $this->render('index');
    }