示例#1
0
 /**
  * @throws \Exception
  * @return CommandResponse
  */
 public function execute()
 {
     $rules = ['title' => 'required|min:3|max:50', 'is_public' => 'required', 'is_pinned' => 'required'];
     $validator = Validator::make($this->_input, $rules);
     if ($validator->fails()) {
         return CommandResponse::fail($validator);
     }
     $this->_playlist->title = $this->_input['title'];
     $this->_playlist->description = $this->_input['description'];
     $this->_playlist->is_public = $this->_input['is_public'] == 'true';
     $this->_playlist->save();
     $pin = PinnedPlaylist::whereUserId(Auth::user()->id)->wherePlaylistId($this->_playlistId)->first();
     if ($pin && $this->_input['is_pinned'] != 'true') {
         $pin->delete();
     } else {
         if (!$pin && $this->_input['is_pinned'] == 'true') {
             $this->_playlist->pin(Auth::user()->id);
         }
     }
     return CommandResponse::succeed(['id' => $this->_playlist->id, 'title' => $this->_playlist->title, 'slug' => $this->_playlist->slug, 'created_at' => $this->_playlist->created_at, 'description' => $this->_playlist->description, 'url' => $this->_playlist->url, 'is_pinned' => $this->_input['is_pinned'] == 'true', 'is_public' => $this->_input['is_public'] == 'true']);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Get list of affected users
     $usernames = DB::table('users')->select(['username', DB::raw('COUNT(*) as count')])->whereNull('disabled_at')->whereNotNull('username')->groupBy(DB::raw('LOWER(username)'))->having('count', '>=', 2)->lists('username');
     foreach ($usernames as $username) {
         // Find the relevant accounts
         // ==========================
         /** @var Collection $accounts */
         $accounts = User::where('username', $username)->orderBy('created_at', 'ASC')->get();
         $firstAccount = $accounts[0];
         $accounts->forget(0);
         $accountIds = $accounts->pluck('id');
         // Reassign content
         // ================
         // This is done with the less-efficient-than-raw-SQL Eloquent
         // methods to generate appropriate revision logs.
         $this->info('Merging duplicates for: ' . $firstAccount->username);
         DB::transaction(function () use($accounts, $accountIds, $firstAccount) {
             foreach (Album::whereIn('user_id', $accountIds)->get() as $album) {
                 $album->user_id = $firstAccount->id;
                 $album->save();
             }
             foreach (Comment::whereIn('user_id', $accountIds)->get() as $comment) {
                 $comment->user_id = $firstAccount->id;
                 $comment->save();
             }
             foreach (Favourite::whereIn('user_id', $accountIds)->get() as $favourite) {
                 $favourite->user_id = $firstAccount->id;
                 $favourite->save();
             }
             foreach (Follower::whereIn('artist_id', $accountIds)->get() as $follow) {
                 $follow->artist_id = $firstAccount->id;
                 $follow->save();
             }
             foreach (Image::whereIn('uploaded_by', $accountIds)->get() as $image) {
                 $image->uploaded_by = $firstAccount->id;
                 $image->save();
             }
             foreach (Image::whereIn('uploaded_by', $accountIds)->get() as $image) {
                 $image->uploaded_by = $firstAccount->id;
                 $image->save();
             }
             DB::table('oauth2_tokens')->whereIn('user_id', $accountIds)->update(['user_id' => $firstAccount->id]);
             foreach (PinnedPlaylist::whereIn('user_id', $accountIds)->get() as $playlist) {
                 $playlist->user_id = $firstAccount->id;
                 $playlist->save();
             }
             foreach (Playlist::whereIn('user_id', $accountIds)->get() as $playlist) {
                 $playlist->user_id = $firstAccount->id;
                 $playlist->save();
             }
             foreach (ResourceLogItem::whereIn('user_id', $accountIds)->get() as $item) {
                 $item->user_id = $firstAccount->id;
                 $item->save();
             }
             foreach (ResourceUser::whereIn('user_id', $accountIds)->get() as $item) {
                 $item->user_id = $firstAccount->id;
                 $item->save();
             }
             foreach (Track::whereIn('user_id', $accountIds)->get() as $track) {
                 $track->user_id = $firstAccount->id;
                 $track->save();
             }
             foreach ($accounts as $account) {
                 $account->disabled_at = Carbon::now();
                 $account->save();
             }
         });
     }
 }
示例#3
0
 public function pin($userId)
 {
     $pin = new PinnedPlaylist();
     $pin->playlist_id = $this->id;
     $pin->user_id = $userId;
     $pin->save();
 }