public function actionIndex($fileName) { Yii::import("application.models.*"); //get the latest idle cron job $dataFolderPath = Yii::getPathOfAlias("application.data"); $filePath = $dataFolderPath . DIRECTORY_SEPARATOR . $fileName; $errorLogFile = $dataFolderPath . DIRECTORY_SEPARATOR . 'RELOAD-LOG.txt'; /*check filename availability*/ if (file_exists($filePath) && is_file($filePath)) { $contents = file_get_contents($filePath); /*read each content of file*/ $fp = fopen($filePath, "rb"); while (!feof($fp)) { $currentLine = fgets($fp); $currentLine = trim($currentLine); $currentLine = "0" . $currentLine; $newBlacklist = new BlackListedMobile(); $newBlacklist->mobile_number = $currentLine; /*check if current mobile number is valid , 07321654987 */ /*if valid save to database*/ if ($newBlacklist->save()) { echo $currentLine . ' SAVED!' . PHP_EOL; } else { file_put_contents($errorLogFile, "ERROR WITH : {$newBlacklist->mobile_number} : ERROR MESSAGE : " . implode(":", $newBlacklist->getErrors("mobile_number")) . " HAVING value : {$newBlacklist->mobile_number}" . PHP_EOL, FILE_APPEND); // echo "ERROR WITH : $currentLine : ERROR MESSAGE : ".CHtml::errorSummary($newBlacklist).PHP_EOL; echo "ERROR WITH : {$newBlacklist->mobile_number} : ERROR MESSAGE : " . implode(":", $newBlacklist->getErrors("mobile_number")) . " HAVING value : {$newBlacklist->mobile_number}" . PHP_EOL; } } } echo PHP_EOL . "RELOADING..... DONE \n"; }
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"; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new BlackListedMobile(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['BlackListedMobile'])) { $model->attributes = $_POST['BlackListedMobile']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->rec_id)); } } $this->render('create', array('model' => $model)); }
public function actionIndex() { header("Content-Type: application/json"); $jsonMessage = array("status" => "error", "message" => "Incomplete parameter"); if (isset($_GET['mobileNumber']) && !empty($_GET['mobileNumber']) && !empty($_GET['ip_address'])) { $mobilenumber1 = new BlackListedMobile('create'); $mobilenumber1->mobile_number = $_GET['mobileNumber']; $mobilenumber1->origin = $_GET['origin']; $mobilenumber1->ip_address = $_GET['ip_address']; if ($mobilenumber1->save()) { $vicidialReport = VicidialReportSend::send($mobilenumber1->mobile_number); $jsonMessage = array("status" => "success", "message" => "Added to blacklisted", 'vicidialRemoteIncludeStatus' => $vicidialReport); } else { $jsonMessage = array("status" => "error", "message" => CHtml::errorSummary($mobilenumber1)); } } else { $jsonMessage = array("status" => "error", "message" => "Invalid mobile number"); } echo json_encode($jsonMessage); }
public function actionIndex($count) { Yii::import("application.models.*"); echo "Preparing to seed blacklisted mobile . "; $dates = array(date("Y-m-d H:i:s", strtotime("monday this week")), date("Y-m-d H:i:s", strtotime("tuesday this week")), date("Y-m-d H:i:s", strtotime("wednesday this week")), date("Y-m-d H:i:s", strtotime("thursday this week")), date("Y-m-d H:i:s", strtotime("friday this week")), date("Y-m-d H:i:s", strtotime("saturday this week")), date("Y-m-d H:i:s", strtotime("sunday this week"))); foreach ($dates as $value) { foreach (range(0, $count) as $value1) { $bl1 = new BlackListedMobile(); $bl1->mobile_number = sprintf("07%d", rand(111111111, 999999999)); $bl1->date_created = $value; $bl1->ip_address = "127.0.0.1"; $bl1->origin = "test"; if ($bl1->save()) { echo "New Mobile number saved:{$value1}" . PHP_EOL; } else { echo "Failed to create new blacklisted mobile" . PHP_EOL; echo CHtml::errorSummary($bl1) . PHP_EOL; echo $bl1->mobile_number; die; } } } }
public function send() { $httpParameters = array("source" => "dncadding", "user" => "apiuserwill", "pass" => "mentalapipassword", "function" => "add_mednc", "dnc_check" => "Y", "phone_number" => $this->getPhoneNumber()); $httpParameters = array_merge($httpParameters, $this->getAdditionalParameters()); $res = $this->sendToRemoteServer($httpParameters); $jsonMessage['vici_res'] = $res; $mdl = new BlackListedMobile(); $mdl->mobile_number = $this->getPhoneNumber(); $mdl->ip_address = $this->getIpAddress(); $mdl->origin = "public_url"; try { if ($mdl->save(false)) { $jsonMessage['dnc.website'] = "saving dnc.website saved"; } else { $jsonMessage['dnc.website'] = "cant save to dnc.website"; $jsonMessage['dnc.website']['message'] = CHtml::errorSummary($mdl); } } catch (Exception $e) { $jsonMessage['dnc.website'] = "fatal error"; $jsonMessage['dnc.website']['message'] = $e->getMessage(); } return $jsonMessage; }
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'); }