コード例 #1
0
ファイル: thread.php プロジェクト: uzura8/flockbird
 public function save_with_relations($member_id, $values)
 {
     if (!empty($this->member_id) && $this->member_id != $member_id) {
         throw new \InvalidArgumentException('Parameter member_id is invalid.');
     }
     $is_new = $this->_is_new;
     $this->member_id = $member_id;
     if (isset($values['title'])) {
         $this->title = $values['title'];
     }
     if (isset($values['body'])) {
         $this->body = $values['body'];
     }
     if (isset($values['public_flag'])) {
         $this->public_flag = $values['public_flag'];
     }
     $is_changed_public_flag = $this->is_changed('public_flag');
     $is_changed = $this->is_changed();
     if ($is_changed) {
         $this->save();
     }
     if (is_enabled('timeline')) {
         if (!$is_new && $is_changed_public_flag) {
             // timeline の public_flag の更新
             \Timeline\Model_Timeline::update_public_flag4foreign_table_and_foreign_id($this->public_flag, 'thread', $this->id, \Config::get('timeline.types.thread'));
         } else {
             // timeline 投稿
             \Timeline\Site_Model::save_timeline($member_id, $this->public_flag, 'thread', $this->id, $this->updated_at);
         }
     }
     return $is_changed;
 }
コード例 #2
0
ファイル: deletealbumimage.php プロジェクト: uzura8/flockbird
 public function before_delete(\Orm\Model $obj)
 {
     // カバー写真の確認 & 削除
     if (!($album = \Album\Model_Album::find($obj->album_id))) {
         throw new \FuelException('Invalid album id.');
     }
     if ($album->cover_album_image_id == $obj->id) {
         $album->cover_album_image_id = null;
         $album->save();
     }
     // プロフィール写真の確認 & 削除
     if ($album->foreign_table == 'member') {
         if ($album->member->file_name == $obj->file_name) {
             $album->member->file_name = null;
             $album->member->save();
         }
         // timeline 投稿の削除
         if (is_enabled('timeline')) {
             \Timeline\Model_Timeline::delete4foreign_table_and_foreign_ids('album_image', $obj->id);
         }
     }
     if (is_enabled('timeline')) {
         // timeline_child_data の削除
         \Timeline\Model_TimelineChildData::delete4foreign_table_and_foreign_ids('album_image', $obj->id);
         // timeline view cache の削除
         if (is_enabled('note') && \Config::get('timeline.articles.cache.is_use') && $obj->album->foreign_table == 'note') {
             \Timeline\Site_Model::delete_note_view_cache4album_image_id($obj->id);
         }
     }
     // file 削除
     if ($file = \Model_File::get4name($obj->file_name)) {
         $file->delete();
     }
 }
コード例 #3
0
 protected function get_timeline(\Orm\Model $obj)
 {
     $query = \Timeline\Model_Timeline::query();
     foreach ($this->_timeline_relations as $property_to => $froms) {
         foreach ($froms as $value_from => $type) {
             $value = \Site_Model::get_value_for_observer_setting($obj, $value_from, $type);
             $query = $query->where($property_to, $value);
         }
     }
     return $query->get_one();
 }
コード例 #4
0
ファイル: deletealbum.php プロジェクト: uzura8/flockbird
 public function before_delete(\Orm\Model $obj)
 {
     // Delete album_image file.
     $album_images = \Album\Model_AlbumImage::get4album_id($obj->id);
     foreach ($album_images as $album_image) {
         $album_image->delete();
     }
     // delete timeline
     if (is_enabled('timeline')) {
         \Timeline\Model_Timeline::delete4foreign_table_and_foreign_ids('album', $obj->id);
     }
 }
コード例 #5
0
ファイル: file.php プロジェクト: uzura8/flockbird
 public static function delete_with_timeline($name)
 {
     if (!($obj = self::get4name($name))) {
         return false;
     }
     if (is_enabled('timeline')) {
         \Timeline\Model_Timeline::delete4foreign_table_and_foreign_ids('file', $obj->id);
     }
     $deleted_filesize = $obj->filesize;
     $obj->delete();
     return $deleted_filesize;
 }
コード例 #6
0
ファイル: model.php プロジェクト: uzura8/flockbird
 public static function get_timelines4foreign_table_and_id($foreign_table, $foreign_id)
 {
     if ($foreign_table == 'timeline') {
         if (!($timeline = \Timeline\Model_Timeline::find($foreign_id))) {
             return false;
         }
         return array($timeline->id => $timeline);
     }
     if (!in_array($foreign_table, \Timeline\Site_Util::get_accept_timeline_foreign_tables())) {
         return false;
     }
     return \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids($foreign_table, $foreign_id);
 }
コード例 #7
0
ファイル: album.php プロジェクト: uzura8/flockbird
 public function update_public_flag_with_relations($public_flag, $is_update_album_images = false)
 {
     // album_image の public_flag の更新
     if ($is_update_album_images) {
         Model_AlbumImage::update_public_flag4album_id($this->id, $public_flag);
     }
     // timeline の public_flag の更新
     if (\Module::loaded('timeline')) {
         \Timeline\Model_Timeline::update_public_flag4foreign_table_and_foreign_id($public_flag, 'album', $this->id, \Config::get('timeline.types.album'));
     }
     $this->public_flag = $public_flag;
     $this->save();
 }
コード例 #8
0
 public function after_delete(\Orm\Model $obj)
 {
     if (!($timeline = \Timeline\Model_Timeline::find($obj->timeline_id))) {
         return;
     }
     $is_cache_delete = false;
     if (!\Timeline\Model_TimelineChildData::get4timeline_id($obj->timeline_id)) {
         $timeline->delete();
         $is_cache_delete = true;
     } elseif ($timeline->update_public_flag_with_check_child_data()) {
         $is_cache_delete = true;
     }
     if (\Config::get('timeline.articles.cache.is_use') && !$is_cache_delete) {
         \Timeline\Site_Util::delete_cache($timeline->id, $timeline->type);
     }
 }
コード例 #9
0
ファイル: notelike.php プロジェクト: uzura8/flockbird
 protected function setUp()
 {
     self::$note_like_count = \Util_Orm::get_count_all('\\Note\\Model_NoteLike', array('note_id' => self::$note_id));
     self::$is_check_view_cache = is_enabled('timeline') && \Config::get('timeline.articles.cache.is_use');
     if (is_enabled('timeline')) {
         $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('note', self::$note_id, \Config::get('timeline.types.note'));
         $timeline = array_shift($timelines);
         self::$timeline_id = $timeline->id;
         self::$timeline_before = $timeline;
     }
     // timeline view cache 作成
     if (self::$is_check_view_cache) {
         \Timeline\Site_Util::get_article_main_view(self::$timeline_id);
         self::$timeline_view_cache_before = \Cache::get(\Timeline\Site_Util::get_cache_key(self::$timeline_id), \Config::get('timeline.articles.cache.expir'));
     }
 }
コード例 #10
0
ファイル: notecomment.php プロジェクト: uzura8/flockbird
 /**
  * @dataProvider save_comment_provider
  */
 public function test_save_comment($member_id, $body)
 {
     // note_comment save
     \Util_Develop::sleep();
     $note_comment = $this->save_comment($member_id, $body);
     $note_id = self::$note_id;
     $note = \DB::select()->from('note')->where('id', $note_id)->execute()->current();
     // 件数
     $comment_count = \Util_Orm::get_count_all('\\Note\\Model_NoteComment', array('note_id' => $note_id));
     $this->assertEquals(self::$note_comment_count + 1, $comment_count);
     // 値
     $this->assertEquals($comment_count, $note['comment_count']);
     $this->assertEquals($note_comment->created_at, $note['sort_datetime']);
     // timeline 関連
     if (is_enabled('timeline')) {
         $timeline_id = self::$timeline_id;
         $timeline = \Timeline\Model_Timeline::find($timeline_id);
         // 値
         $this->assertEquals($comment_count, $timeline->comment_count);
         $this->assertEquals($note_comment->created_at, $timeline->sort_datetime);
         $this->assertEquals($note['sort_datetime'], $timeline->sort_datetime);
         $timeline_caches = \DB::select()->from('timeline_cache')->where('timeline_id', $timeline_id)->execute();
         // timeline_caches
         $this->assertCount(2, $timeline_caches);
         foreach ($timeline_caches as $timeline_cache) {
             $this->assertEquals($comment_count, $timeline_cache['comment_count']);
         }
         // timeline_cache が最新レコードになっているか
         $timeline_cache = \Util_Orm::get_last_row('\\Timeline\\Model_TimelineCache');
         $this->assertEquals($timeline_id, $timeline_cache->timeline_id);
         // timeline view cache check
         if (self::$is_check_view_cache) {
             $timeline_view_cache = \Cache::get(\Timeline\Site_Util::get_cache_key($timeline_id), \Config::get('timeline.articles.cache.expir'));
             $this->assertEquals(self::$view_cache_before, $timeline_view_cache);
         }
     }
 }
コード例 #11
0
ファイル: note.php プロジェクト: uzura8/flockbird
 public function delete_with_relations()
 {
     // album_image の削除
     if (\Module::loaded('album') && ($album_images = Model_NoteAlbumImage::get_album_image4note_id($this->id))) {
         $album_image_ids = array();
         foreach ($album_images as $album_image) {
             $album_image_ids[] = $album_image->id;
         }
         \Album\Model_AlbumImage::delete_multiple($album_image_ids);
     }
     // timeline 投稿の削除
     if (\Module::loaded('timeline')) {
         \Timeline\Model_Timeline::delete4foreign_table_and_foreign_ids('note', $this->id);
     }
     // note の削除
     $this->delete();
 }
コード例 #12
0
ファイル: util.php プロジェクト: uzura8/flockbird
 public static function make_view_cache4foreign_table_and_foreign_id($foreign_table, $foreign_id, $type = null)
 {
     $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids($foreign_table, $foreign_id, $type);
     $timeline = array_shift($timelines);
     Site_Util::get_article_main_view($timeline->id);
     return \Cache::get(\Timeline\Site_Util::get_cache_key($timeline->id), \Config::get('timeline.articles.cache.expir'));
 }
コード例 #13
0
ファイル: album.php プロジェクト: uzura8/flockbird
 public function test_delete_with_relations()
 {
     if (!($album = $this->get_album())) {
         \Util_Develop::output_test_info(__FILE__, __LINE__);
         $this->markTestSkipped();
     }
     $album_id = $album->id;
     $member_id = $album->member_id;
     $album_filesize_total = self::get_album_filesize_total($album_id);
     $member_filesize_before = self::get_member_filesize_total($member_id);
     $album->delete();
     // 件数
     // album
     $this->assertEquals(self::$album_count - 1, \Util_Orm::get_count_all('\\Album\\Model_Album'));
     // album_image
     $album_images = Model_AlbumImage::get4album_id($album_id);
     $this->assertEmpty($album_images);
     // filesize
     $this->assertEquals($member_filesize_before - $album_filesize_total, self::get_member_filesize_total($member_id));
     // timeline
     if (is_enabled('timeline')) {
         $this->assertEquals(self::$timeline_count - 1, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline'));
         $this->assertEquals(self::$timeline_cache_count - 2, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache'));
         $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('album', $album_id, \Config::get('timeline.types.album'));
         $this->assertEmpty($timelines);
     }
 }
コード例 #14
0
ファイル: albumimage.php プロジェクト: uzura8/flockbird
 /**
  * @dataProvider update_public_flag_provider
  */
 public function test_update_public_flag($default_public_flag, $public_flag, $timeline_public_flag_expected)
 {
     if (!self::$album_image || !is_null($default_public_flag)) {
         self::$album_image = $this->get_album_image(array('public_flag' => $default_public_flag), 2);
     }
     $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('album', self::$album_image->album_id, \Config::get('timeline.types.album_image'));
     $timeline_before = array_shift($timelines);
     // 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'));
     }
     $before = array('public_flag' => self::$album_image->public_flag, 'created_at' => self::$album_image->created_at, 'updated_at' => self::$album_image->updated_at);
     // update public_flag
     \Util_Develop::sleep();
     self::$album_image->update_public_flag($public_flag);
     $is_updated = $public_flag != $before['public_flag'];
     // 値
     $this->assertEquals($public_flag, self::$album_image->public_flag);
     // date
     // 変更あり
     if ($is_updated) {
         $this->assertTrue(\Util_Date::check_is_future(self::$album_image->updated_at, $before['updated_at']));
     } else {
         $this->assertEquals($before['updated_at'], self::$album_image->updated_at);
     }
     // timeline
     if (is_enabled('timeline')) {
         // 件数
         $this->assertEquals(self::$timeline_count, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline'));
         $this->assertEquals(self::$timeline_cache_count, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache'));
         $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('album', self::$album_image->album_id, \Config::get('timeline.types.album_image'));
         $timeline = array_shift($timelines);
         $this->assertEquals($timeline_public_flag_expected, $timeline->public_flag);
         // 変更あり
         if ($is_updated) {
             if (\Site_Util::check_is_expanded_public_flag_range($before['public_flag'], $public_flag)) {
                 $this->assertTrue(\Util_Date::check_is_future($timeline->sort_datetime, self::$album_image->created_at));
             }
         } else {
             $this->assertEquals($timeline_before->updated_at, $timeline->updated_at);
         }
         // timeline view cache check
         if (self::$is_check_timeline_view_cache) {
             $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline->id));
         }
     }
 }
コード例 #15
0
ファイル: albumimage.php プロジェクト: uzura8/flockbird
 public function update_public_flag($public_flag, $is_skip_check_album_disabled_to_update = false)
 {
     if (!$is_skip_check_album_disabled_to_update && ($result = Site_Util::check_album_disabled_to_update($this->album->foreign_table))) {
         throw new \DisableToUpdateException($result['message']);
     }
     $this->public_flag = $public_flag;
     $result = $this->save();
     if (\Module::loaded('timeline')) {
         \Timeline\Model_Timeline::check_and_update_public_flag4child_data($public_flag, 'album_image', $this->id);
     }
     return $result;
 }
コード例 #16
0
ファイル: model.php プロジェクト: uzura8/flockbird
 public static function delete_note_view_cache4album_image_id($album_image_id)
 {
     if (!($note_id = \Note\Model_NoteAlbumImage::get_note_id4album_image_id($album_image_id))) {
         return;
     }
     if (!($timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('note', $note_id))) {
         return;
     }
     $timeline = array_shift($timelines);
     \Timeline\Site_Util::delete_cache($timeline->id, $timeline->type);
 }
コード例 #17
0
ファイル: note.php プロジェクト: uzura8/flockbird
 /**
  * @dataProvider update_public_flag_with_relations_provider
  */
 public function test_update_public_flag_with_relations($public_flag)
 {
     $note = $this->get_last_row();
     $before = array('public_flag' => $note->public_flag, 'updated_at' => $note->updated_at, 'sort_datetime' => $note->sort_datetime);
     $note->update_public_flag_with_relations($public_flag);
     // 件数
     $this->assertEquals(self::$note_count, \Util_Orm::get_count_all('\\Note\\Model_Note'));
     // 値
     $this->assertEquals($public_flag, $note->public_flag);
     // date
     // 変更なし
     if ($note->public_flag == $before['public_flag']) {
         $this->assertEquals($before['updated_at'], $note->updated_at);
         $this->assertEquals($before['sort_datetime'], $note->sort_datetime);
     } else {
         $this->assertTrue(\Util_Date::check_is_future($note->updated_at, $note->created_at));
         $this->assertEquals($note->updated_at, $note->sort_datetime);
     }
     // timeline
     if (is_enabled('timeline')) {
         $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('note', $note->id, \Config::get('timeline.types.note'));
         if ($note->is_published) {
             $this->assertCount(1, $timelines);
             $timeline = array_shift($timelines);
             $this->assertEquals($note->public_flag, $timeline->public_flag);
             $this->assertEquals($note->sort_datetime, $timeline->sort_datetime);
         } else {
             $this->assertCount(0, $timelines);
         }
     }
 }
コード例 #18
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));
             }
         }
     }
 }