Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into install-eloquent-dr…
Browse files Browse the repository at this point in the history
…iver-command
  • Loading branch information
duncanmcclean committed Apr 11, 2024
2 parents 43f5aaf + 7f34ead commit b00c71b
Show file tree
Hide file tree
Showing 46 changed files with 646 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ jobs:
name: Slack Notification
runs-on: ubuntu-20.04
needs: [php-tests, js-tests]
if: always() && github.event_name == 'schedule'
if: always()
steps:
- uses: technote-space/workflow-conclusion-action@v1
- name: Send Slack notification
uses: 8398a7/action-slack@v2
if: env.WORKFLOW_CONCLUSION == 'failure'
if: env.WORKFLOW_CONCLUSION == 'failure' && github.event_name == 'schedule'
with:
status: failure
author_name: ${{ github.actor }}
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes

## 5.0.0-alpha.2 (2024-04-10)

### What's changed
- Change tag parameter parse-prevention character from @ to backslash. [#9856](https://github.com/statamic/cms/issues/9856) by @jasonvarga
- Revert requirement of prefixing attributes with `:attr`. [#9854](https://github.com/statamic/cms/issues/9854) by @jasonvarga



## 5.0.0-alpha.1 (2024-04-09)

### What's new
Expand Down
21 changes: 19 additions & 2 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,29 @@ public function save()
return true;
}

/**
* Delete quietly without firing events.
*
* @return bool
*/
public function deleteQuietly()
{
$this->withEvents = false;

return $this->delete();
}

/**
* Delete the asset.
*
* @return $this
*/
public function delete()
{
if (AssetDeleting::dispatch($this) === false) {
$withEvents = $this->withEvents;
$this->withEvents = true;

if ($withEvents && AssetDeleting::dispatch($this) === false) {
return false;
}

Expand All @@ -653,7 +668,9 @@ public function delete()

$this->clearCaches();

AssetDeleted::dispatch($this);
if ($withEvents) {
AssetDeleted::dispatch($this);
}

return $this;
}
Expand Down
19 changes: 18 additions & 1 deletion src/Assets/AssetContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Statamic\Events\AssetContainerCreated;
use Statamic\Events\AssetContainerCreating;
use Statamic\Events\AssetContainerDeleted;
use Statamic\Events\AssetContainerDeleting;
use Statamic\Events\AssetContainerSaved;
use Statamic\Events\AssetContainerSaving;
use Statamic\Facades;
Expand Down Expand Up @@ -262,16 +263,32 @@ public function save()
return $this;
}

public function deleteQuietly()
{
$this->withEvents = false;

return $this->delete();
}

/**
* Delete the container.
*
* @return void
*/
public function delete()
{
$withEvents = $this->withEvents;
$this->withEvents = true;

if ($withEvents && AssetContainerDeleting::dispatch($this) === false) {
return false;
}

Facades\AssetContainer::delete($this);

AssetContainerDeleted::dispatch($this);
if ($withEvents) {
AssetContainerDeleted::dispatch($this);
}

return true;
}
Expand Down
16 changes: 14 additions & 2 deletions src/Auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,27 @@ public function save()
return $this;
}

public function deleteQuietly()
{
$this->withEvents = false;

return $this->delete();
}

public function delete()
{
if (UserDeleting::dispatch($this) === false) {
$withEvents = $this->withEvents;
$this->withEvents = true;

if ($withEvents && UserDeleting::dispatch($this) === false) {
return false;
}

Facades\User::delete($this);

UserDeleted::dispatch($this);
if ($withEvents) {
UserDeleted::dispatch($this);
}

return $this;
}
Expand Down
55 changes: 41 additions & 14 deletions src/Entries/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Collection implements Arrayable, ArrayAccess, AugmentableContract, Contrac
protected $titleFormats = [];
protected $previewTargets = [];
protected $autosave;
protected $withEvents = true;

public function __construct()
{
Expand Down Expand Up @@ -459,16 +460,28 @@ public function createLabel()
return $translation;
}

public function saveQuietly()
{
$this->withEvents = false;

return $this->save();
}

public function save()
{
$isNew = ! Facades\Collection::handleExists($this->handle);

if ($isNew && CollectionCreating::dispatch($this) === false) {
return false;
}
$withEvents = $this->withEvents;
$this->withEvents = true;

if (CollectionSaving::dispatch($this) === false) {
return false;
if ($withEvents) {
if ($isNew && CollectionCreating::dispatch($this) === false) {
return false;
}

if (CollectionSaving::dispatch($this) === false) {
return false;
}
}

Facades\Collection::save($this);
Expand All @@ -477,11 +490,13 @@ public function save()
Blink::forget('mounted-collections');
Blink::flushStartingWith("collection-{$this->id()}");

if ($isNew) {
CollectionCreated::dispatch($this);
}
if ($withEvents) {
if ($isNew) {
CollectionCreated::dispatch($this);
}

CollectionSaved::dispatch($this);
CollectionSaved::dispatch($this);
}

return $this;
}
Expand Down Expand Up @@ -748,15 +763,25 @@ public function hasStructure()
return $this->structure !== null || $this->structureContents !== null;
}

public function deleteQuietly()
{
$this->withEvents = false;

return $this->delete();
}

public function delete()
{
if (CollectionDeleting::dispatch($this) === false) {
$withEvents = $this->withEvents;
$this->withEvents = true;

if ($withEvents && CollectionDeleting::dispatch($this) === false) {
return false;
}

$this->queryEntries()->get()->each(function ($entry) {
$entry->deleteDescendants();
$entry->delete();
$this->queryEntries()->get()->each(function ($entry) use ($withEvents) {
$entry->deleteDescendants($withEvents);
$withEvents ? $entry->delete() : $entry->deleteQuietly();
});

if ($this->hasStructure()) {
Expand All @@ -765,7 +790,9 @@ public function delete()

Facades\Collection::delete($this);

CollectionDeleted::dispatch($this);
if ($withEvents) {
CollectionDeleted::dispatch($this);
}

Blink::forget('mounted-collections');

Expand Down
24 changes: 18 additions & 6 deletions src/Entries/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,19 @@ public function getCurrentDirtyStateAttributes(): array
], $this->data()->except(['updated_at'])->toArray());
}

public function deleteQuietly()
{
$this->withEvents = false;

return $this->delete();
}

public function delete()
{
if (EntryDeleting::dispatch($this) === false) {
$withEvents = $this->withEvents;
$this->withEvents = true;

if ($withEvents && EntryDeleting::dispatch($this) === false) {
return false;
}

Expand All @@ -223,16 +233,18 @@ public function delete()

Facades\Entry::delete($this);

EntryDeleted::dispatch($this);
if ($withEvents) {
EntryDeleted::dispatch($this);
}

return true;
}

public function deleteDescendants()
public function deleteDescendants($withEvents = true)
{
$this->descendants()->each(function ($entry) {
$entry->deleteDescendants();
$entry->delete();
$this->descendants()->each(function ($entry) use ($withEvents) {
$entry->deleteDescendants($withEvents);
$withEvents ? $entry->delete() : $entry->deleteQuietly();
});

Blink::forget('entry-descendants-'.$this->id());
Expand Down
23 changes: 23 additions & 0 deletions src/Events/AssetContainerDeleting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Statamic\Events;

class AssetContainerDeleting extends Event
{
public $container;

public function __construct($container)
{
$this->container = $container;
}

/**
* Dispatch the event with the given arguments, and halt on first non-null listener response.
*
* @return mixed
*/
public static function dispatch()
{
return event(new static(...func_get_args()), [], true);
}
}
2 changes: 1 addition & 1 deletion src/Extend/AddonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function setUp(): void
$this->withoutMix();
$this->withoutVite();

Version::shouldReceive('get')->andReturn(Composer::create(__DIR__.'/../')->installedVersion(Statamic::PACKAGE));
Version::shouldReceive('get')->zeroOrMoreTimes()->andReturn(Composer::create(__DIR__.'/../')->installedVersion(Statamic::PACKAGE));
$this->addToAssertionCount(-1);

\Statamic\Facades\CP\Nav::shouldReceive('build')->zeroOrMoreTimes()->andReturn(collect());
Expand Down
16 changes: 14 additions & 2 deletions src/Fields/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,27 @@ public function save()
return $this;
}

public function deleteQuietly()
{
$this->withEvents = false;

return $this->delete();
}

public function delete()
{
if (BlueprintDeleting::dispatch($this) === false) {
$withEvents = $this->withEvents;
$this->withEvents = true;

if ($withEvents && BlueprintDeleting::dispatch($this) === false) {
return false;
}

BlueprintRepository::delete($this);

BlueprintDeleted::dispatch($this);
if ($withEvents) {
BlueprintDeleted::dispatch($this);
}

return true;
}
Expand Down
16 changes: 14 additions & 2 deletions src/Fields/Fieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,27 @@ public function save()
return $this;
}

public function deleteQuietly()
{
$this->withEvents = false;

return $this->delete();
}

public function delete()
{
if (FieldsetDeleting::dispatch($this) === false) {
$withEvents = $this->withEvents;
$this->withEvents = true;

if ($withEvents && FieldsetDeleting::dispatch($this) === false) {
return false;
}

FieldsetRepository::delete($this);

FieldsetDeleted::dispatch($this);
if ($withEvents) {
FieldsetDeleted::dispatch($this);
}

return true;
}
Expand Down
Loading

0 comments on commit b00c71b

Please sign in to comment.