Esempio n. 1
0
 /**
  * Upload attachment to server.
  *
  * @param Base\Model $resource Currently processed resource.
  *
  * @static
  * @access public
  *
  * @return void
  */
 public static function upload(Base\Model $resource)
 {
     foreach (self::$attachments as $name => $_attachment) {
         $_error_uploading = false;
         $_attachment_name = $resource->{$name};
         if (self::$isUploading[$name]) {
             $successful = Helpers\File::upload($_FILES[$name], $resource->attachmentsStoragePath($name), $_attachment_name);
             if ($successful) {
                 /* Make thumbnails */
                 if ($_attachment['type'] === array('photo') && isset($_attachment['thumbnails']) && is_array($_attachment['thumbnails'])) {
                     self::createThumbnails($resource, $name, $_attachment_name, $_attachment['thumbnails']);
                 }
             } else {
                 $_error_uploading = true;
             }
         }
         /* Delete old attachment and its related files */
         if (!$_error_uploading) {
             $attachment_old_file = Core\Config()->paths('root') . $resource->attachmentsStoragePath($name) . self::$attachmentsOld[$name];
             if (self::$attachmentsOld[$name] != $_attachment_name && file_exists($attachment_old_file)) {
                 try {
                     Helpers\File::delete($attachment_old_file);
                 } catch (\Exception $e) {
                     /* @todo Explain why we are not handling exception. */
                 }
                 if ($_attachment['type'] === array('photo') && isset($_attachment['thumbnails']) && is_array($_attachment['thumbnails'])) {
                     self::deleteThumbnails($resource, $name, self::$attachmentsOld[$name]);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * @covers Core\Helpers\File::upload
  */
 public function testUploadingUnsuccessfully()
 {
     /* Mock built-in function move_uploaded_file to return FALSE */
     $this->moveUploadedFile->expects($this->once())->willReturn(false);
     $this->assertFalse(File::upload($_FILES['test'], Core\Config()->paths('root'), $this->uploadedFile));
 }