-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14032 from craftcms/feature/acc-349-bulk-element-…
…operation-tracking Bulk element operation tracking + event
- Loading branch information
Showing
15 changed files
with
906 additions
and
520 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
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
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,22 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\events; | ||
|
||
/** | ||
* Bulk operation event class. | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 5.0.0 | ||
*/ | ||
class BulkOpEvent extends ElementQueryEvent | ||
{ | ||
/** | ||
* @var string The bulk operation key. | ||
*/ | ||
public string $key; | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace craft\migrations; | ||
|
||
use craft\db\Migration; | ||
use craft\db\Table; | ||
|
||
/** | ||
* m231213_030600_element_bulk_ops migration. | ||
*/ | ||
class m231213_030600_element_bulk_ops extends Migration | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeUp(): bool | ||
{ | ||
$this->createTable(Table::ELEMENTS_BULKOPS, [ | ||
'elementId' => $this->integer(), | ||
'key' => $this->char(10)->notNull(), | ||
'timestamp' => $this->dateTime()->notNull(), | ||
'PRIMARY KEY([[elementId]], [[key]])', | ||
]); | ||
$this->addForeignKey(null, Table::ELEMENTS_BULKOPS, ['elementId'], Table::ELEMENTS, ['id'], 'CASCADE', null); | ||
$this->createIndex(null, Table::ELEMENTS_BULKOPS, ['timestamp'], false); | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function safeDown(): bool | ||
{ | ||
echo "m231213_030600_element_bulk_ops cannot be reverted.\n"; | ||
return false; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\queue; | ||
|
||
use Craft; | ||
|
||
/** | ||
* BaseBatchedElementJob is the base class for large jobs that may need to spawn | ||
* additional jobs to complete the workload, which perform actions on elements. | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 5.0.0 | ||
*/ | ||
abstract class BaseBatchedElementJob extends BaseBatchedJob | ||
{ | ||
/** @internal */ | ||
public string $bulkOpKey; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function before(): void | ||
{ | ||
$this->bulkOpKey = Craft::$app->getElements()->beginBulkOp(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function beforeBatch(): void | ||
{ | ||
Craft::$app->getElements()->resumeBulkOp($this->bulkOpKey); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function after(): void | ||
{ | ||
Craft::$app->getElements()->endBulkOp($this->bulkOpKey); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
use craft\helpers\Db; | ||
use craft\helpers\ElementHelper; | ||
use craft\i18n\Translation; | ||
use craft\queue\BaseBatchedJob; | ||
use craft\queue\BaseBatchedElementJob; | ||
use craft\services\Structures; | ||
use Throwable; | ||
|
||
|
@@ -30,7 +30,7 @@ | |
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 3.4.8 | ||
*/ | ||
class ApplyNewPropagationMethod extends BaseBatchedJob | ||
class ApplyNewPropagationMethod extends BaseBatchedElementJob | ||
{ | ||
/** | ||
* @var string The element type to use | ||
|
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 |
---|---|---|
|
@@ -14,15 +14,15 @@ | |
use craft\db\QueryBatcher; | ||
use craft\helpers\ElementHelper; | ||
use craft\i18n\Translation; | ||
use craft\queue\BaseBatchedJob; | ||
use craft\queue\BaseBatchedElementJob; | ||
|
||
/** | ||
* PropagateElements job | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 3.0.13 | ||
*/ | ||
class PropagateElements extends BaseBatchedJob | ||
class PropagateElements extends BaseBatchedElementJob | ||
{ | ||
/** | ||
* @var string The element type that should be propagated | ||
|
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
use craft\db\QueryBatcher; | ||
use craft\helpers\ElementHelper; | ||
use craft\i18n\Translation; | ||
use craft\queue\BaseBatchedJob; | ||
use craft\queue\BaseBatchedElementJob; | ||
use Throwable; | ||
|
||
/** | ||
|
@@ -24,7 +24,7 @@ | |
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 3.0.0 | ||
*/ | ||
class ResaveElements extends BaseBatchedJob | ||
class ResaveElements extends BaseBatchedElementJob | ||
{ | ||
/** | ||
* @var string The element type that should be resaved | ||
|
Oops, something went wrong.