Pony.fm/app/models/Commands/DeleteTrackCommand.php

40 lines
822 B
PHP
Raw Normal View History

2013-07-25 23:33:04 +02:00
<?php
namespace Commands;
use Entities\Track;
class DeleteTrackCommand extends CommandBase {
private $_trackId;
private $_track;
function __construct($trackId) {
$this->_trackId = $trackId;
$this->_track = Track::find($trackId);
}
/**
* @return bool
*/
public function authorize() {
$user = \Auth::user();
return $this->_track && $user != null && $this->_track->user_id == $user->id;
}
/**
* @throws \Exception
* @return CommandResponse
*/
public function execute() {
2013-07-28 19:45:21 +02:00
if ($this->_track->album_id != null) {
$album = $this->_track->album;
$this->_track->album_id = null;
$this->_track->track_number = null;
$this->_track->delete();
$album->updateTrackNumbers();
} else
$this->_track->delete();
2013-07-25 23:33:04 +02:00
return CommandResponse::succeed();
}
}