Пример #1
0
 /**
  * Imports crash report files for certain project version.
  * @param string $dirName  Directory name.
  * @param string $projectId Project ID.
  * @param string $projVer  Project version.
  * @return integer count of crash report imported; or -1 on error.
  */
 private function importCrashReports($dirName, $projectId, $projVerId)
 {
     //echo 'Importing crash report files from dir: '.$dirName.'\n';
     // Get file list in the directory
     $fileList = scandir($dirName);
     if ($fileList == false) {
         Yii::log('Directory name is invalid: ' . $dirName, 'error');
         return -1;
         // Error
     }
     // Walk through files
     foreach ($fileList as $index => $file) {
         // Get abs path
         $path = $dirName . '/' . $file;
         // Strip file parts
         $path_parts = pathinfo($path);
         if ($file != '.' && $file != '..' && is_file($path) && strtolower($path_parts['extension']) == 'zip') {
             //echo 'Importing crash report file: '.$path.'\n';
             // Create new AR record
             $crashReport = new CrashReport();
             $crashReport->project_id = $projectId;
             $crashReport->appversion = $projVerId;
             $crashReport->fileAttachment = new CUploadedFile($file, $path, 'application/zip', filesize($path), '');
             // The following is to copy attachment file correctly.
             $crashReport->fileAttachmentIsUploaded = false;
             // Save changes to database
             if (!$crashReport->save()) {
                 Yii::log('Could not import crash report file:' . $path, 'error');
                 $errors = $crashReport->getErrors();
                 //var_dump($errors);
             } else {
                 // Increment counter
                 $this->_importedCrashReportsCount++;
             }
         }
     }
     // Done
     return $this->_importedCrashReportsCount;
 }