コード例 #1
0
ファイル: DebugInfoTest.php プロジェクト: xyzz/CrashFix
 public function testCreate()
 {
     // Login as root
     $model = new LoginForm('RegularLogin');
     $model->username = "******";
     $model->password = "******";
     $this->assertTrue($model->login());
     // Create temp file
     $tmpfile1 = tempnam(Yii::app()->getRuntimePath(), "test");
     $tmpfile = $tmpfile1 . '.pdb';
     $f = fopen($tmpfile, 'w');
     fwrite($f, 'MZP1234567');
     fclose($f);
     // Create new model
     $model = new DebugInfo('create');
     $model->ignoreFileAttachmentErrors = true;
     // This is to ignore errors
     $model->project_id = 1;
     $model->guid = 'tmp_12345678901234456745';
     $model->fileAttachment = new CUploadedFile('CrashRptd.pdb', $tmpfile, 'application/octet-stream', 5, 0);
     // Apply changes
     $saved = $model->save();
     $this->assertTrue($saved);
     // Try to save again - should fail (GUID already exists)
     // Create new model
     $model2 = new DebugInfo('create');
     $model2->ignoreFileAttachmentErrors = true;
     // This is to ignore errors
     $model2->project_id = 1;
     $model2->guid = 'tmp_12345678901234456745';
     $model2->fileAttachment = new CUploadedFile('CrashRptd.pdb', $tmpfile, 'application/octet-stream', 5, 0);
     // Apply changes
     $saved2 = $model2->save();
     $this->assertFalse($saved2);
     // Remove temp file
     unlink($tmpfile);
     unlink($tmpfile1);
 }
コード例 #2
0
ファイル: BatchImporter.php プロジェクト: xyzz/CrashFix
 /**
  * Imports debug info files for certain project version.
  * @param string $dirName  Directory name.
  * @param string $projectId Project ID.
  * @param string $projVer  Project version.
  * @return integer count of debug info files imported; or -1 on error.
  */
 private function importDebugInfo($dirName, $projectId, $projVerId)
 {
     //echo 'Importing debug info 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;
     }
     // Walk through files
     foreach ($fileList as $file) {
         // Get abs path
         $path = $dirName . '/' . $file;
         // Strip file parts
         $path_parts = pathinfo($path);
         if ($file != '.' && $file != '..' && is_file($path) && strtolower($path_parts['extension']) == 'pdb') {
             //echo 'Importing debug info file: '.$path.'\n';
             // Create new AR record
             $debugInfo = new DebugInfo();
             $debugInfo->project_id = $projectId;
             $debugInfo->guid = 'tmp_' . MiscHelpers::GUID();
             $debugInfo->fileAttachment = new CUploadedFile($file, $path, 'application/zip', filesize($path), '');
             // The following is to copy attachment file correctly.
             $debugInfo->fileAttachmentIsUploaded = false;
             // Save changes to database
             if (!$debugInfo->save()) {
                 Yii::log('Could not import debug info file:' . $path, 'error');
             } else {
                 $this->_importedDebugInfoCount++;
             }
         }
     }
     // Done
     return $this->_importedDebugInfoCount;
 }