File events refactoring
This commit is contained in:
@@ -5,7 +5,6 @@ namespace Kanboard\Model;
|
||||
use Exception;
|
||||
use Kanboard\Core\Base;
|
||||
use Kanboard\Core\Thumbnail;
|
||||
use Kanboard\Event\FileEvent;
|
||||
use Kanboard\Core\ObjectStorage\ObjectStorageException;
|
||||
|
||||
/**
|
||||
@@ -44,13 +43,13 @@ abstract class FileModel extends Base
|
||||
abstract protected function getPathPrefix();
|
||||
|
||||
/**
|
||||
* Get event name
|
||||
* Fire file creation event
|
||||
*
|
||||
* @abstract
|
||||
* @access protected
|
||||
* @return string
|
||||
* @param integer $file_id
|
||||
*/
|
||||
abstract protected function getEventName();
|
||||
abstract protected function fireCreationEvent($file_id);
|
||||
|
||||
/**
|
||||
* Get PicoDb query to get all files
|
||||
@@ -130,16 +129,16 @@ abstract class FileModel extends Base
|
||||
* Create a file entry in the database
|
||||
*
|
||||
* @access public
|
||||
* @param integer $id Foreign key
|
||||
* @param string $name Filename
|
||||
* @param string $path Path on the disk
|
||||
* @param integer $size File size
|
||||
* @param integer $foreign_key_id Foreign key
|
||||
* @param string $name Filename
|
||||
* @param string $path Path on the disk
|
||||
* @param integer $size File size
|
||||
* @return bool|integer
|
||||
*/
|
||||
public function create($id, $name, $path, $size)
|
||||
public function create($foreign_key_id, $name, $path, $size)
|
||||
{
|
||||
$values = array(
|
||||
$this->getForeignKey() => $id,
|
||||
$this->getForeignKey() => $foreign_key_id,
|
||||
'name' => substr($name, 0, 255),
|
||||
'path' => $path,
|
||||
'is_image' => $this->isImage($name) ? 1 : 0,
|
||||
@@ -152,8 +151,7 @@ abstract class FileModel extends Base
|
||||
|
||||
if ($result) {
|
||||
$file_id = (int) $this->db->getLastId();
|
||||
$event = new FileEvent($values + array('file_id' => $file_id));
|
||||
$this->dispatcher->dispatch($this->getEventName(), $event);
|
||||
$this->fireCreationEvent($file_id);
|
||||
return $file_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,14 +61,13 @@ class ProjectFileModel extends FileModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event name
|
||||
* Fire file creation event
|
||||
*
|
||||
* @abstract
|
||||
* @access protected
|
||||
* @return string
|
||||
* @param integer $file_id
|
||||
*/
|
||||
protected function getEventName()
|
||||
protected function fireCreationEvent($file_id)
|
||||
{
|
||||
return self::EVENT_CREATE;
|
||||
$this->queueManager->push($this->projectFileEventJob->withParams($file_id, self::EVENT_CREATE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,18 +60,6 @@ class TaskFileModel extends FileModel
|
||||
return 'tasks';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event name
|
||||
*
|
||||
* @abstract
|
||||
* @access protected
|
||||
* @return string
|
||||
*/
|
||||
protected function getEventName()
|
||||
{
|
||||
return self::EVENT_CREATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get projectId from fileId
|
||||
*
|
||||
@@ -101,4 +89,15 @@ class TaskFileModel extends FileModel
|
||||
$original_filename = e('Screenshot taken %s', $this->helper->dt->datetime(time())).'.png';
|
||||
return $this->uploadContent($task_id, $original_filename, $blob);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire file creation event
|
||||
*
|
||||
* @access protected
|
||||
* @param integer $file_id
|
||||
*/
|
||||
protected function fireCreationEvent($file_id)
|
||||
{
|
||||
$this->queueManager->push($this->taskFileEventJob->withParams($file_id, self::EVENT_CREATE));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user