Example #1
0
 public function run($args)
 {
     exit('Disabled');
     $time_start = microtime(true);
     $path = Yii::app()->basePath . '/../../protected-file-uploads/cleaning-company/to-process/';
     print "\n\n" . 'Looking for data in ' . $path . "\n\n";
     //$files = glob($path . '*.csv');
     $CFiles = CleaningFile::model()->findAllByAttributes(array('status' => 0));
     if ($CFiles) {
         foreach ($CFiles as $CFile) {
             //$CFile->status = 1;
             //$CFile->save();
             // if (!$CFile->save()) {
             // 	print_r($CFile->getErrors());
             // }
             $file = $path . '/' . $CFile->uuid . '.csv';
             if (file_exists($file)) {
                 $this->importCSV($file, $CFile->uuid);
                 // Delete File
                 unlink(Yii::app()->basePath . '/../../protected-file-uploads/cleaning-company/to-process/' . $CFile->uuid . '.csv');
                 $CFile->status = 1;
                 $CFile->import_date = date('Y-m-d H:i:s');
                 $CFile->save();
             } else {
                 print "\n" . 'File ' . $file . ' does not exist and was skipped' . "\n";
             }
         }
     }
     $time_end = microtime(true);
     $execution_time = round(($time_end - $time_start) / 60, 2);
     //execution time of the script
     print "\n\n" . 'Total Execution Time: ' . $execution_time . ' mins' . "\n\n";
     print count($CFiles) . ' files processed' . "\n\n";
     exit;
 }
Example #2
0
 /**
  * This is the default 'view' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionCleaningUpload()
 {
     $CleaningFile = new CleaningFile();
     $Uploads = null;
     if (isset($_POST['CleaningFile'])) {
         if ($CleaningFile->save()) {
             $subPath = 'cleaning-company/to-process';
             $filename = Yii::app()->basePath . '/../../protected-file-uploads/' . $subPath . '/' . $CleaningFile->uuid . ".csv";
             if (!@move_uploaded_file($_FILES['CleaningFile']['tmp_name']['data'], $filename)) {
                 Yii::app()->user->setFlash('error', 'There was a problem uploading the file');
                 $CleaningFile->delete();
             } else {
                 Yii::app()->user->setFlash('success', 'Thanks, your CSV has been successfully uploaded and we will process it shortly.');
                 $this->refresh();
             }
         }
     }
     $Uploads = CleaningFile::model()->findAll();
     $this->pageTitle = 'Cleaning Data | ' . Yii::app()->name;
     $this->breadcrumbs = array('Cleaning Data Upload');
     $this->render('upload-cleaning', array('Success' => $Saved, 'CleaningFile' => $CleaningFile, 'Uploads' => $Uploads));
 }