Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Add various events #10459

Merged
merged 17 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Actions/Impersonate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Events\NullDispatcher;
use Illuminate\Support\Facades\Auth;
use Statamic\Contracts\Auth\User as UserContract;
use Statamic\Events\ImpersonationStarted;
use Statamic\Facades\CP\Toast;
use Statamic\Facades\User;

Expand Down Expand Up @@ -45,11 +46,14 @@ public function run($users, $values)
}

try {
$currentUser = $guard->user();
$impersonator = $guard->user();
$impersonated = $users->first();

$guard->login($users->first());
session()->put('statamic_impersonated_by', $currentUser->getKey());
Toast::success(__('You are now impersonating').' '.$users->first()->name());
session()->put('statamic_impersonated_by', $impersonator->getKey());
Toast::success(__('You are now impersonating').' '.$impersonated->name());

ImpersonationStarted::dispatch($impersonator, $impersonated);
} finally {
if ($dispatcher) {
$guard->setDispatcher($dispatcher);
Expand Down
3 changes: 3 additions & 0 deletions src/Console/Commands/GlideClear.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Statamic\Console\RunsInPlease;
use Statamic\Events\GlideCacheCleared;
use Statamic\Facades\File;
use Statamic\Facades\Glide;
use Statamic\Filesystem\Filesystem;
Expand Down Expand Up @@ -46,6 +47,8 @@ public function handle()

$this->deleteEmptyDirectories($disk);

GlideCacheCleared::dispatch();

$this->info('Your Glide image cache is now so very, very empty.');
}

Expand Down
3 changes: 3 additions & 0 deletions src/Console/Commands/LicenseSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Console\ConfirmableTrait;
use Statamic\Console\EnhancesCommands;
use Statamic\Console\RunsInPlease;
use Statamic\Events\LicenseSet as LicenseSetEvent;

class LicenseSet extends Command
{
Expand Down Expand Up @@ -42,6 +43,8 @@ public function handle()

$this->laravel['config']['statamic.system.license_key'] = $key;

LicenseSetEvent::dispatch();

$this->checkInfo('Statamic license key set successfully.');
}

Expand Down
7 changes: 7 additions & 0 deletions src/Events/GlideCacheCleared.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Statamic\Events;

class GlideCacheCleared extends Event
{
}
10 changes: 10 additions & 0 deletions src/Events/ImpersonationEnded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Statamic\Events;

class ImpersonationEnded extends Event
{
public function __construct(public $impersonator, public $impersonated)
{
}
}
10 changes: 10 additions & 0 deletions src/Events/ImpersonationStarted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Statamic\Events;

class ImpersonationStarted extends Event
{
public function __construct(public $impersonator, public $impersonated)
{
}
}
7 changes: 7 additions & 0 deletions src/Events/LicenseSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Statamic\Events;

class LicenseSet extends Event
{
}
7 changes: 7 additions & 0 deletions src/Events/LicensesRefreshed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Statamic\Events;

class LicensesRefreshed extends Event
{
}
10 changes: 10 additions & 0 deletions src/Events/SearchIndexUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Statamic\Events;

class SearchIndexUpdated extends Event
{
public function __construct(public $index)
{
}
}
7 changes: 7 additions & 0 deletions src/Events/StacheCleared.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Statamic\Events;

class StacheCleared extends Event
{
}
7 changes: 7 additions & 0 deletions src/Events/StacheWarmed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Statamic\Events;

class StacheWarmed extends Event
{
}
7 changes: 7 additions & 0 deletions src/Events/StaticCacheCleared.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Statamic\Events;

class StaticCacheCleared extends Event
{
}
10 changes: 10 additions & 0 deletions src/Events/UserPasswordChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Statamic\Events;

class UserPasswordChanged extends Event
{
public function __construct(public $user)
{
}
}
4 changes: 4 additions & 0 deletions src/Http/Controllers/CP/Auth/ImpersonationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Events\NullDispatcher;
use Illuminate\Support\Facades\Auth;
use Statamic\Events\ImpersonationEnded;
use Statamic\Facades\User;

class ImpersonationController
Expand All @@ -19,6 +20,7 @@ public function stop()
$guard->setDispatcher(new NullDispatcher($dispatcher));
}

$impersonatedUser = User::current();
$originalUser = User::find($originalUserId);

if ($originalUser) {
Expand All @@ -28,6 +30,8 @@ public function stop()
if ($dispatcher) {
$guard->setDispatcher($dispatcher);
}

ImpersonationEnded::dispatch($originalUser, $impersonatedUser);
}

return redirect()->route('statamic.cp.users.index');
Expand Down
3 changes: 3 additions & 0 deletions src/Http/Controllers/CP/Users/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Request;
use Illuminate\Validation\Rules\Password;
use Statamic\Events\UserPasswordChanged;
use Statamic\Exceptions\NotFoundHttpException;
use Statamic\Facades\User;
use Statamic\Http\Controllers\CP\CpController;
Expand All @@ -28,6 +29,8 @@ public function update(Request $request, $user)

$user->password($request->password)->save();

UserPasswordChanged::dispatch($user);

return response('', 204);
}
}
8 changes: 7 additions & 1 deletion src/Http/Controllers/CP/Utilities/UpdateSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Http\Controllers\CP\Utilities;

use Illuminate\Http\Request;
use Statamic\Events\SearchIndexUpdated;
use Statamic\Facades\Search;
use Statamic\Http\Controllers\CP\CpController;
use Statamic\Support\Str;
Expand All @@ -17,10 +18,15 @@ public function update(Request $request)

$indexes->each(function ($index) {
[$name, $locale] = explode('::', $index);

if ($locale) {
$name = Str::before($name, '_'.$locale);
}
Search::index($name, $locale ?: null)->update();

$index = Search::index($name, $locale ?: null);
$index->update();

SearchIndexUpdated::dispatch($index);
duncanmcclean marked this conversation as resolved.
Show resolved Hide resolved
});

return back()->withSuccess(__('Update successful.'));
Expand Down
3 changes: 3 additions & 0 deletions src/Licensing/LicenseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Carbon;
use Illuminate\Support\MessageBag;
use Statamic\Events\LicensesRefreshed;
use Statamic\Support\Arr;

class LicenseManager
Expand Down Expand Up @@ -116,6 +117,8 @@ public function addons()
public function refresh()
{
$this->outpost->clearCachedResponse();

LicensesRefreshed::dispatch();
}

public function usingLicenseKeyFile()
Expand Down
4 changes: 4 additions & 0 deletions src/Search/Commands/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Statamic\Console\RunsInPlease;
use Statamic\Events\SearchIndexUpdated;
use Statamic\Facades\Search;
use Statamic\Support\Str;

Expand All @@ -23,6 +24,9 @@ public function handle()
{
foreach ($this->getIndexes() as $index) {
$index->update();

SearchIndexUpdated::dispatch($index);
duncanmcclean marked this conversation as resolved.
Show resolved Hide resolved

$this->info("Index <comment>{$index->name()}</comment> updated.");
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/Stache/Stache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Statamic\Events\StacheCleared;
use Statamic\Events\StacheWarmed;
use Statamic\Extensions\FileStore;
use Statamic\Facades\File;
use Statamic\Stache\Stores\Store;
Expand Down Expand Up @@ -92,6 +94,8 @@ public function clear()

$this->cacheStore()->forget('stache::timing');

StacheCleared::dispatch();

return $this;
}

Expand All @@ -111,6 +115,8 @@ public function warm()
$this->stopTimer();

$lock->release();

StacheWarmed::dispatch();
}

public function instance()
Expand Down
5 changes: 5 additions & 0 deletions src/StaticCaching/StaticCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Cache\Repository;
use Illuminate\Support\Facades\Cache;
use Statamic\Events\StaticCacheCleared;
use Statamic\Facades\Site;
use Statamic\StaticCaching\Cachers\ApplicationCacher;
use Statamic\StaticCaching\Cachers\FileCacher;
Expand Down Expand Up @@ -68,6 +69,8 @@ public function flush()
if ($this->hasCustomStore()) {
$this->cacheStore()->flush();

StaticCacheCleared::dispatch();

return;
}

Expand All @@ -78,6 +81,8 @@ public function flush()
});

$this->cacheStore()->forget('nocache::urls');

StaticCacheCleared::dispatch();
}

public function nocacheJs(string $js)
Expand Down
Loading