-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate on enable and setting change
- Loading branch information
Showing
5 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace IanM\BoringAvatars\Extend; | ||
|
||
use Flarum\Extend\ExtenderInterface; | ||
use Flarum\Extend\LifecycleInterface; | ||
use Flarum\Extension\Extension; | ||
use IanM\BoringAvatars\Job\AvatarGenerationJob; | ||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Contracts\Queue\Queue; | ||
|
||
class Lifecycle implements ExtenderInterface, LifecycleInterface | ||
{ | ||
public function onEnable(Container $container, Extension $extension): void | ||
{ | ||
$container->make(Queue::class) | ||
->push(new AvatarGenerationJob()); | ||
} | ||
|
||
public function onDisable(Container $container, Extension $extension) | ||
{ | ||
// Do nothing | ||
} | ||
|
||
public function extend(Container $container, Extension $extension = null) | ||
{ | ||
// Do nothing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace IanM\BoringAvatars\Job; | ||
|
||
use Flarum\Queue\AbstractJob; | ||
use IanM\BoringAvatars\Console\GenerateBoringAvatars; | ||
use Illuminate\Contracts\Container\Container; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
|
||
class AvatarGenerationJob extends AbstractJob | ||
{ | ||
public function handle(GenerateBoringAvatars $command, Container $container): void | ||
{ | ||
$command->setLaravel($container); | ||
|
||
$command->run(new ArrayInput(['--force' => true]), new NullOutput()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace IanM\BoringAvatars\Listener; | ||
|
||
use Flarum\Settings\Event\Saved; | ||
use IanM\BoringAvatars\Job\AvatarGenerationJob; | ||
use Illuminate\Contracts\Queue\Queue; | ||
use Illuminate\Support\Str; | ||
|
||
class SettingsChanged | ||
{ | ||
public function __construct( | ||
protected Queue $queue | ||
) { | ||
} | ||
|
||
public function __invoke(Saved $event) | ||
{ | ||
$settings = $event->settings; | ||
|
||
// Check if any keys in the settings array start with 'ianm-boring-avatars.' | ||
$prefix = 'ianm-boring-avatars.'; | ||
$keysWithPrefix = array_filter($settings, function (string $key) use ($prefix) { | ||
return Str::startsWith($key, $prefix); | ||
}, ARRAY_FILTER_USE_KEY); | ||
|
||
if (!empty($keysWithPrefix)) { | ||
$this->queue->push(new AvatarGenerationJob()); | ||
} | ||
} | ||
} |