コード例 #1
0
ファイル: file.php プロジェクト: uzura8/flockbird
 public static function move_from_file_tmp(Model_FileTmp $file_tmp, $new_filename_prefix = '', $upload_type = 'img')
 {
     $file = static::forge();
     $file->name = $file_tmp->name;
     if ($new_filename_prefix) {
         $file->name = Site_Upload::change_filename_prefix($file_tmp->name, $new_filename_prefix);
     }
     $file->filesize = $file_tmp->filesize;
     $file->original_filename = $file_tmp->original_filename;
     $file->type = $file_tmp->type;
     $file->member_id = $file_tmp->member_id;
     $file->user_type = $file_tmp->user_type;
     if (!is_null($file_tmp->exif)) {
         $file->exif = $file_tmp->exif;
     }
     if (!empty($file_tmp->shot_at)) {
         $file->shot_at = $file_tmp->shot_at;
     }
     $file->save();
     if (conf('upload.storageType') == 'db') {
         $file_bin = Model_FileBin::get4name($file_tmp->name);
         $file_bin->name = $file->name;
         $file_bin->save();
     } elseif (conf('upload.storageType') == 'S3') {
         Site_S3::move($file_tmp->name, $file->name, $upload_type);
     }
     $file_tmp->delete();
     return $file;
 }
コード例 #2
0
ファイル: File.php プロジェクト: uzura8/flockbird
 public function test_file_exists()
 {
     foreach ($this->files as $file) {
         if ($this->is_save_db) {
             $this->assertNotNull(\Model_FileBin::get4name($file->name));
         } else {
             $this->assertFileExists(self::check_and_get_file_path($file->path, $file->name));
         }
     }
 }
コード例 #3
0
ファイル: removefile.php プロジェクト: uzura8/flockbird
 protected function delete_stored_file(\Orm\Model $obj)
 {
     if (conf('upload.storageType') == 'normal') {
         return;
     }
     if ($this->_is_tmp && \Model_File::get4name($obj->name)) {
         return;
     }
     if (conf('upload.storageType') == 'S3') {
         return \Site_S3::delete($obj->name, 'img') && \Site_S3::delete($obj->name, 'file');
     }
     if (!($file_bin = \Model_FileBin::get4name($obj->name))) {
         return;
     }
     return $file_bin->delete();
 }
コード例 #4
0
ファイル: uploader.php プロジェクト: uzura8/flockbird
 protected function save_file_bin($tmp_file_path)
 {
     switch ($this->options['storage_type']) {
         case 'db':
             $storage_save_result = (bool) Model_FileBin::save_from_file_path($tmp_file_path, $this->file->name);
             break;
         case 'S3':
             $storage_save_result = (bool) Site_S3::save($tmp_file_path, null, $this->options['upload_type']);
             break;
         case 'normal':
         default:
             $storage_save_result = true;
             break;
     }
     if (!$storage_save_result) {
         Util_File::remove($tmp_file_path);
         throw new FuelException('Save raw file error to storage.');
     }
     if (!($result = (bool) Util_file::move($tmp_file_path, $this->file->file_path))) {
         throw new FuelException('Save raw file error.');
     }
     return $storage_save_result && $result;
 }
コード例 #5
0
ファイル: upload.php プロジェクト: uzura8/flockbird
 public static function get_bin_from_storage($filename, $strage_type = null, $upload_type = 'img')
 {
     if (!$strage_type) {
         $strage_type = conf('upload.storageType');
     }
     if (!in_array($strage_type, array('db', 'S3'))) {
         throw new InvalidArgumentException('Second parameter is invalid.');
     }
     return $strage_type == 'db' ? Model_FileBin::get_bin4name($filename) : file_get_contents(Site_S3::get_url($filename, $upload_type));
 }
コード例 #6
0
ファイル: noormmodel.php プロジェクト: uzura8/flockbird
 public function test_delete_album_image_multiple4ids()
 {
     $timeline_ids = array_unique(\Util_Orm::conv_col2array(\Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image_id', self::$album_image->id), 'timeline_id'));
     $notices = array();
     if (is_enabled('notice')) {
         $notice_ids = \Util_Orm::conv_col2array(\Notice\Model_Notice::get4foreign_data('album_image', self::$album_image->id), 'id');
         $notice_ids += \Util_Orm::conv_col2array(\Notice\Model_Notice::get4parent_data('album_image', self::$album_image->id), 'id');
         $notice_ids = array_unique($notice_ids);
     }
     $notice_statuses = \Notice\Model_NoticeStatus::query()->where('notice_id', 'in', $notice_ids)->get();
     $file_name = self::$album_image->file_name;
     $file = \Model_File::get4name($file_name);
     $file_size = $file->filesize;
     $member_filesize_before = self::$member->filesize_total;
     // timeline view cache 作成
     if (self::$is_check_timeline_view_cache) {
         $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('album', $album->id, \Config::get('timeline.types.album_image'));
     }
     // file
     if (conf('upload.storageType') == 'db') {
         $this->assertNotNull(\Model_FileBin::get4name(self::$album_image->file_name));
     }
     // album_image delete.
     Site_NoOrmModel::delete_album_image_multiple4ids(self::$album_image->id, true);
     // 件数
     $this->assertEmpty(Model_AlbumImage::query()->where('id', self::$album_image->id)->get());
     $this->assertEmpty(Model_AlbumImageLike::query()->where('album_image_id', self::$album_image_comment->id)->get());
     $this->assertEmpty(Model_AlbumImageComment::query()->where('album_image_id', self::$album_image->id)->get());
     $this->assertEmpty(Model_AlbumImageCommentLike::query()->where('album_image_comment_id', self::$album_image_comment->id)->get());
     // file
     $this->assertEmpty(\Model_File::get4name($file_name));
     // meber_filesize
     $this->assertEquals($member_filesize_before - $file_size, self::get_member_filesize_total(self::$member_id));
     // timeline
     if (is_enabled('timeline')) {
         $timeline_child_datas = \Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image', self::$album_image->id);
         $this->assertEmpty($timeline_child_datas);
         if ($timeline_ids) {
             $this->assertEmpty(\Timeline\Model_Timeline::query()->where('id', 'in', $timeline_ids)->get());
         }
         // timeline view cache check
         if (self::$is_check_timeline_view_cache && $timeline_ids) {
             foreach ($timeline_ids as ${$timeline_id}) {
                 $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline_id));
             }
         }
     }
     // notice
     if (is_enabled('notice')) {
         $this->assertEmpty(\Notice\Model_MemberWatchContent::get4foreign_data('album_image', self::$album_image->id));
         if ($notice_ids) {
             $this->assertEmpty(\Notice\Model_Notice::query()->where('id', 'in', $notice_ids)->get());
             $this->assertEmpty(\Notice\Model_NoticeStatus::query()->where('notice_id', 'in', $notice_ids)->get());
             $this->assertEmpty(\Notice\Model_NoticeMemberFrom::query()->where('notice_id', 'in', $notice_ids)->get());
         }
         if (self::$is_check_notice_cache) {
             foreach ($notice_statuses as $notice_statuse) {
                 $this->assertEmpty(\Notice\Site_Util::get_unread_count_cache($notice_statuse->member_id));
             }
         }
     }
 }
コード例 #7
0
ファイル: albumimage.php プロジェクト: uzura8/flockbird
 public function test_delete()
 {
     if (!self::$album_image) {
         self::$album_image = $this->get_album_image(array('public_flag' => FBD_PUBLIC_FLAG_MEMBER));
     }
     $album_image_id = self::$album_image->id;
     $file_name = self::$album_image->file_name;
     $file = \Model_File::get4name($file_name);
     $file_size = $file->filesize;
     $file_path = \Site_Upload::get_uploaded_file_path(self::$album_image->file_name);
     $member_filesize_before = self::get_member_filesize_total(self::$member_id);
     // set cover_album_image_id
     self::$album->cover_album_image_id = $album_image_id;
     // timeline view cache 作成
     if (self::$is_check_timeline_view_cache) {
         $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('album', $album->id, \Config::get('timeline.types.album_image'));
     }
     // file
     if (conf('upload.storageType') == 'db') {
         $this->assertNotNull(\Model_FileBin::get4name(self::$album_image->file_name));
     } elseif (conf('upload.storageType') == 'normal') {
         $this->assertTrue(file_exists($file_path));
     }
     // album_image delete.
     self::$album_image->delete();
     // 件数
     $this->assertEquals(self::$total_count - 1, Model_AlbumImage::get_count());
     // file
     $this->assertEmpty(\Model_File::get4name($file_name));
     $this->assertFalse(file_exists($file_path));
     // meber_filesize
     $this->assertEquals($member_filesize_before - $file_size, self::get_member_filesize_total(self::$member_id));
     // check cover_album_image_id
     $this->assertEmpty(self::$album->cover_album_image_id);
     // timeline
     if (is_enabled('timeline')) {
         $timeline_child_datas = \Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image', $album_image_id);
         $this->assertEmpty($timeline_child_datas);
         // timeline view cache check
         if (self::$is_check_timeline_view_cache) {
             $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline->id));
         }
     }
 }
コード例 #8
0
ファイル: myuploadhandler.php プロジェクト: uzura8/flockbird
 protected function delete_file($filename, $storage_type = 'normal', $is_delete_raw_file_only = false, $is_delete_with_storage_data = true)
 {
     $filename_excluded_prefix = str_replace($this->options['filename_prefix'], '', $filename);
     $file_path = $this->get_upload_path($filename_excluded_prefix);
     $success = is_file($file_path) && unlink($file_path);
     if ($success && !$is_delete_raw_file_only) {
         foreach ($this->options['image_versions'] as $version => $options) {
             if (!empty($version)) {
                 $varsion_file = $this->get_upload_path($filename_excluded_prefix, $version);
                 if (is_file($varsion_file)) {
                     unlink($varsion_file);
                 }
             }
         }
     }
     if (!$is_delete_with_storage_data) {
         return $success;
     }
     if ($storage_type == 'db') {
         if ($file_bin = Model_FileBin::get4name($filename)) {
             $success = (bool) $file_bin->delete();
         }
     } elseif ($storage_type == 'S3') {
         $success = (bool) Site_S3::delete($filename, $this->options['upload_type']);
     }
     return $success;
 }