Exemple #1
0
 public static function delete_album_image_multiple4ids($album_image_ids = array(), $with_delete_timeline = false)
 {
     if (!is_array($album_image_ids)) {
         $album_image_ids = (array) $album_image_ids;
     }
     $delete_target_notice_cache_member_ids = array();
     $delete_target_timeline_ids = array();
     $writable_connection = \MyOrm\Model::connection(true);
     \DBUtil::set_connection($writable_connection);
     \DB::start_transaction();
     foreach ($album_image_ids as $album_image_id) {
         if (is_enabled('notice')) {
             \Notice\Site_NoOrmModel::delete_member_watch_content_multiple4foreign_data('album_image', $album_image_id);
             $notice_ids = \Notice\Site_NoOrmModel::get_notice_ids4foreign_data('album_image', $album_image_id);
             $delete_target_notice_cache_member_ids += \Notice\Site_NoOrmModel::get_notice_status_member_ids4notice_ids($notice_ids);
             \Notice\Site_NoOrmModel::delete_notice_multiple4ids($notice_ids);
         }
         if (is_enabled('timeline') && $with_delete_timeline) {
             $delete_target_timeline_ids += \timeline\site_noormmodel::delete_timeline_multiple4foreign_data('album_image', $album_image_id);
         }
     }
     $file_names = \Util_Orm::conv_col2array(Model_AlbumImage::get4ids($album_image_ids), 'file_name');
     \DB::delete('album_image')->where('id', 'in', $album_image_ids)->execute();
     \DB::commit_transaction();
     \DBUtil::set_connection(null);
     \DB::start_transaction();
     if ($files = \Model_File::get4names($file_names)) {
         foreach ($files as $file) {
             $file->delete();
         }
     }
     \DB::commit_transaction();
     // delete caches
     if ($delete_target_notice_cache_member_ids) {
         foreach ($delete_target_notice_cache_member_ids as $member_id) {
             \Notice\Site_Util::delete_unread_count_cache($member_id);
         }
     }
     if ($delete_target_timeline_ids) {
         foreach ($delete_target_timeline_ids as $timeline_id) {
             \Timeline\Site_Util::delete_cache($timeline_id);
         }
     }
 }