Skip to content

Commit

Permalink
Update commands to use dispatchSync (for Laravel 10)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanwatt committed Sep 5, 2023
1 parent 47af0c1 commit 3f8abce
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 61 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"source": "https://github.com/anomalylabs/files-module"
},
"require": {
"anomaly/streams-platform": "^1.6"
"anomaly/streams-platform": "^1.10"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Anomaly\FilesModule\File\FileRepository;
use Anomaly\Streams\Platform\Database\Migration\Migration;
use Anomaly\Streams\Platform\Model\EloquentModel;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Anomaly\Streams\Platform\Entry\Command\AutoloadEntryModels;

/**
Expand All @@ -17,8 +16,6 @@
*/
class AnomalyModuleFilesAddStrIdToFiles extends Migration
{
use DispatchesJobs;

/**
* Don't delete the stream.
* Used for reference only.
Expand Down Expand Up @@ -61,7 +58,7 @@ public function up()
/**
* Make sure that the File entry model has been loaded before we attempt to interact with it.
*/
$this->dispatchNow(new AutoloadEntryModels());
dispatch_sync(new AutoloadEntryModels());


/**
Expand Down
26 changes: 11 additions & 15 deletions src/Disk/Adapter/AdapterFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Anomaly\FilesModule\Disk\Adapter\Command\SyncFile;
use Anomaly\FilesModule\Disk\Adapter\Command\SyncFolder;
use Anomaly\FilesModule\Disk\Contract\DiskInterface;
use Illuminate\Foundation\Bus\DispatchesJobs;
use InvalidArgumentException;
use League\Flysystem\AdapterInterface;
use League\Flysystem\FileExistsException;
Expand All @@ -24,9 +23,6 @@
*/
class AdapterFilesystem extends Filesystem implements FilesystemInterface
{

use DispatchesJobs;

/**
* The base URL.
*
Expand Down Expand Up @@ -73,7 +69,7 @@ public function write($path, $contents, array $config = [])
$result = parent::write($path, $contents, $config);

if ($result && $resource = $this->get($path)) {
return $this->dispatch(new SyncFile($resource));
return dispatch_sync(new SyncFile($resource));
}

return $result;
Expand All @@ -96,7 +92,7 @@ public function writeStream($path, $resource, array $config = [])
$result = parent::writeStream($path, $resource, $config);

if ($result && $resource = $this->get($path)) {
return $this->dispatch(new SyncFile($resource));
return dispatch_sync(new SyncFile($resource));
}

return $result;
Expand All @@ -118,7 +114,7 @@ public function update($path, $contents, array $config = [])
$result = parent::update($path, $contents, $config);

if ($result && $resource = $this->get($path)) {
return $this->dispatch(new SyncFile($resource));
return dispatch_sync(new SyncFile($resource));
}

return $result;
Expand All @@ -141,7 +137,7 @@ public function updateStream($path, $resource, array $config = [])
$result = parent::updateStream($path, $resource, $config);

if ($result && $resource = $this->get($path)) {
return $this->dispatch(new SyncFile($resource));
return dispatch_sync(new SyncFile($resource));
}

return $result;
Expand All @@ -161,7 +157,7 @@ public function put($path, $contents, array $config = [])
$sync = array_get($config, 'sync', true);

if ($result && $sync !== false && $resource = $this->get($path)) {
return $this->dispatch(new SyncFile($resource));
return dispatch_sync(new SyncFile($resource));
}

return $result;
Expand All @@ -179,7 +175,7 @@ public function putStream($path, $resource, array $config = [])
$result = parent::putStream($path, $resource, $config);

if ($result && $resource = $this->get($path)) {
return $this->dispatch(new SyncFile($resource));
return dispatch_sync(new SyncFile($resource));
}

return $result;
Expand All @@ -201,7 +197,7 @@ public function copy($path, $newpath)
$result = parent::copy($path, $newpath);

if ($result && $resource = $this->get($newpath)) {
return $this->dispatch(
return dispatch_sync(
new SyncFile($resource)
);
}
Expand All @@ -219,7 +215,7 @@ public function rename($from, $to)
$result = parent::rename($from, $to);

if ($result && $resource = $this->get($to)) {
return $this->dispatch(
return dispatch_sync(
new RenameFile($resource, $from)
);
}
Expand All @@ -243,7 +239,7 @@ public function delete($path)
$result = parent::delete($path);

if ($result && $resource) {
return $this->dispatch(new DeleteFile($resource));
return dispatch_sync(new DeleteFile($resource));
}

return $result;
Expand All @@ -263,7 +259,7 @@ public function deleteDir($dirname)
$result = parent::deleteDir($dirname);

if ($result && $this->has($dirname)) {
return $this->dispatch(new DeleteFolder($this->get($dirname)));
return dispatch_sync(new DeleteFolder($this->get($dirname)));
}

return $result;
Expand All @@ -282,7 +278,7 @@ public function createDir($dirname, array $config = [])
$result = parent::createDir($dirname, $config);

if ($result && $resource = $this->get($dirname)) {
return $this->dispatch(new SyncFolder($resource));
return dispatch_sync(new SyncFolder($resource));
}

return $result;
Expand Down
6 changes: 1 addition & 5 deletions src/File/Command/GetMaxUploadSize.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace Anomaly\FilesModule\File\Command;

use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
use Illuminate\Foundation\Bus\DispatchesJobs;

/**
* Class GetMaxUploadSize
Expand All @@ -12,9 +11,6 @@
*/
class GetMaxUploadSize
{

use DispatchesJobs;

/**
* Handle the command.
*
Expand All @@ -25,7 +21,7 @@ public function handle(SettingRepositoryInterface $settings)
{
$setting = $settings->value('anomaly.module.files::max_upload_size', 100);

$system = $this->dispatch(new GetSystemMaxUploadSize());
$system = dispatch_sync(new GetSystemMaxUploadSize());

return $system < $setting ? $system : $setting;
}
Expand Down
2 changes: 1 addition & 1 deletion src/File/FileCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FileCriteria extends EntryCriteria
public function folder($identifier)
{
/* @var FolderInterface $folder */
$folder = $this->dispatch(new GetFolder($identifier));
$folder = dispatch_sync(new GetFolder($identifier));

$stream = $folder->getEntryStream();
$table = $stream->getEntryTableName();
Expand Down
2 changes: 1 addition & 1 deletion src/File/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function move($from, $to)
$result = $this->manager->put($to, $contents = $this->manager->read($from), ['sync' => false]);

if ($result && $this->manager->has($to)) {
$result = dispatch_now(new MoveFile($from, $to));
$result = dispatch_sync(new MoveFile($from, $to));
}

$this->manager->delete($from);
Expand Down
9 changes: 5 additions & 4 deletions src/File/FileModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ public function filesystem()
}

/**
* Return the file resource.
* Return the file resource.
*
* @return null|File
*/
public function resource()
{
return $this->dispatch(new GetResource($this));
return dispatch_sync(new GetResource($this));
}

/**
Expand Down Expand Up @@ -194,7 +195,7 @@ public function make()
*/
public function image()
{
return $this->dispatch(new GetImage($this));
return dispatch_sync(new GetImage($this));
}

/**
Expand All @@ -204,7 +205,7 @@ public function image()
*/
public function type()
{
return $this->dispatch(new GetType($this));
return dispatch_sync(new GetType($this));
}

/**
Expand All @@ -215,7 +216,7 @@ public function type()
*/
public function canPreview()
{
return $this->dispatch(new GetPreviewSupport($this));
return dispatch_sync(new GetPreviewSupport($this));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/File/FileObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FileObserver extends EntryObserver
*/
public function creating(EntryInterface $entry)
{
$this->dispatchNow(new SetStrId($entry));
dispatch_sync(new SetStrId($entry));

parent::creating($entry);
}
Expand All @@ -42,7 +42,7 @@ public function saving(EntryInterface $entry)
* make sure to set dimensions.
*/
if ($entry->resource()) {
$this->dispatch(new SetDimensions($entry));
dispatch_sync(new SetDimensions($entry));
}

return parent::saving($entry);
Expand All @@ -55,7 +55,7 @@ public function saving(EntryInterface $entry)
*/
public function deleting(EntryInterface $entry)
{
$this->dispatch(new DeleteResource($entry));
dispatch_sync(new DeleteResource($entry));

parent::deleting($entry);
}
Expand Down
8 changes: 2 additions & 6 deletions src/File/FilePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Anomaly\Streams\Platform\Entry\EntryPresenter;
use Anomaly\Streams\Platform\Support\Decorator;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Routing\UrlGenerator;
use Intervention\Image\Constraint;
Expand All @@ -21,9 +20,6 @@
*/
class FilePresenter extends EntryPresenter
{

use DispatchesJobs;

/**
* The decorated object.
* This is for IDE support.
Expand Down Expand Up @@ -184,7 +180,7 @@ function (Constraint $constraint) {
}
}

$type = $this->dispatch(new GetType($this->object)) ?: 'document';
$type = dispatch_sync(new GetType($this->object)) ?: 'document';

return $this->image
->make('anomaly.module.files::img/types/' . $type . '.png')
Expand All @@ -205,7 +201,7 @@ public function thumbnail($width = 64, $height = 64)
return $this->object->image()->fit($width, $height)->output();
}

$type = $this->dispatch(new GetType($this->object)) ?: 'document';
$type = dispatch_sync(new GetType($this->object)) ?: 'document';

return $this->image
->make('anomaly.module.files::img/types/' . $type . '.png')
Expand Down
6 changes: 3 additions & 3 deletions src/FilesModulePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ public function getFunctions()
new \Twig_SimpleFunction(
'max_upload_size',
function () {
return $this->dispatch(new GetMaxUploadSize());
return dispatch_sync(new GetMaxUploadSize());
}
),
new \Twig_SimpleFunction(
'file',
function ($identifier) {
return (new Decorator())->decorate($this->dispatch(new GetFile($identifier)));
return (new Decorator())->decorate(dispatch_sync(new GetFile($identifier)));
}
),
new \Twig_SimpleFunction(
'folder',
function ($identifier) {
return (new Decorator())->decorate($this->dispatch(new GetFolder($identifier)));
return (new Decorator())->decorate(dispatch_sync(new GetFolder($identifier)));
}
),
];
Expand Down
7 changes: 1 addition & 6 deletions src/FilesModuleSeeder.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php namespace Anomaly\FilesModule;

use Anomaly\FilesModule\Disk\Command\LoadDisks;
use Anomaly\FilesModule\Disk\Command\RegisterDisks;
use Anomaly\FilesModule\Disk\DiskSeeder;
use Anomaly\FilesModule\Folder\FolderSeeder;
use Anomaly\Streams\Platform\Database\Seeder\Seeder;
use Illuminate\Foundation\Bus\DispatchesJobs;

/**
* Class FilesModuleSeeder
Expand All @@ -16,17 +14,14 @@
*/
class FilesModuleSeeder extends Seeder
{

use DispatchesJobs;

/**
* Run the seeder.
*/
public function run()
{
$this->call(DiskSeeder::class);

$this->dispatch(new LoadDisks());
dispatch_sync(new LoadDisks());

$this->call(FolderSeeder::class);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FilesModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function map(FieldRouter $fields, VersionRouter $versions, AssignmentRout
public function boot()
{
if ($this->addon->isEnabled()) {
$this->dispatch(new LoadDisks());
//dispatch_sync(new LoadDisks());
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/Folder/Command/CreateStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use Anomaly\FilesModule\Folder\Contract\FolderInterface;
use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface;
use Illuminate\Contracts\Config\Repository;
use Illuminate\Foundation\Bus\DispatchesJobs;

/**
* Class CreateStream
Expand All @@ -14,9 +13,6 @@
*/
class CreateStream
{

use DispatchesJobs;

/**
* The file folder instance.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Folder/FolderModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getEntryModelName()
*/
public function getEntryStream()
{
return $this->dispatch(new GetStream($this));
return dispatch_sync(new GetStream($this));
}

/**
Expand Down
Loading

0 comments on commit 3f8abce

Please sign in to comment.