-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/4.2.2' into main
- Loading branch information
Showing
73 changed files
with
475 additions
and
192 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
101 changes: 101 additions & 0 deletions
101
src/console/controllers/utils/FixFieldLayoutUidsController.php
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,101 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\console\controllers\utils; | ||
|
||
use Craft; | ||
use craft\console\Controller; | ||
use craft\helpers\Console; | ||
use craft\helpers\StringHelper; | ||
use yii\console\ExitCode; | ||
|
||
/** | ||
* Fixes any duplicate UUIDs found within field layout components in the project config. | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
* @since 4.2.3 | ||
*/ | ||
class FixFieldLayoutUidsController extends Controller | ||
{ | ||
/** | ||
* Fixes any duplicate UUIDs found within field layout components in the project config. | ||
* | ||
* @return int | ||
*/ | ||
public function actionIndex(): int | ||
{ | ||
$this->stdout("Looking for duplicate UUIDs ...\n"); | ||
$count = 0; | ||
$this->_fixUids(Craft::$app->getProjectConfig()->get(), $count); | ||
|
||
if ($count) { | ||
$summary = sprintf('Fixed %s duplicate %s.', $count, $count === 1 ? 'UUID' : 'UUIDs'); | ||
} else { | ||
$summary = 'No duplicate UUIDs were found.'; | ||
} | ||
|
||
$this->stdout('Done. ', Console::FG_GREEN); | ||
$this->stdout("$summary\n"); | ||
|
||
|
||
return ExitCode::OK; | ||
} | ||
|
||
private function _fixUids(array $config, int &$count, string $path = '', array &$uids = []): void | ||
{ | ||
if (isset($config['fieldLayouts']) && is_array($config['fieldLayouts'])) { | ||
$modified = false; | ||
|
||
foreach ($config['fieldLayouts'] as $fieldLayoutUid => &$fieldLayoutConfig) { | ||
if (isset($fieldLayoutConfig['tabs']) && is_array($fieldLayoutConfig['tabs'])) { | ||
foreach ($fieldLayoutConfig['tabs'] as $tabIndex => &$tabConfig) { | ||
$tabPath = ($path ? "$path." : '') . "fieldLayouts.$fieldLayoutUid.tabs.$tabIndex"; | ||
$this->_checkUid($tabConfig, $count, $uids, $modified, $tabPath); | ||
|
||
if (isset($tabConfig['elements']) && is_array($tabConfig['elements'])) { | ||
foreach ($tabConfig['elements'] as $elementIndex => &$elementConfig) { | ||
$elementPath = "$tabPath.elements.$elementIndex"; | ||
$this->_checkUid($elementConfig, $count, $uids, $modified, $elementPath); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ($modified) { | ||
Craft::$app->getProjectConfig()->set($path, $config); | ||
} | ||
|
||
return; | ||
} | ||
|
||
foreach ($config as $key => $value) { | ||
if (is_array($value)) { | ||
$this->_fixUids($value, $count, ($path ? "$path." : '') . $key, $uids); | ||
} | ||
} | ||
} | ||
|
||
private function _checkUid(array &$config, int &$count, array &$uids, bool &$modified, string $path): void | ||
{ | ||
if (isset($config['uid'])) { | ||
if (isset($uids[$config['uid']])) { | ||
$config['uid'] = StringHelper::UUID(); | ||
$count++; | ||
$modified = true; | ||
|
||
$this->stdout(' > Duplicate found at '); | ||
$this->stdout($path, Console::FG_CYAN); | ||
$this->stdout(".\n Changing to "); | ||
$this->stdout($config['uid'], Console::FG_CYAN); | ||
$this->stdout(".\n"); | ||
} else { | ||
$uids[$config['uid']] = true; | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
/** | ||
* Delete represents a Delete element action. | ||
* | ||
* Element types that make this action available should implement [[ElementInterface::getIsDeletable()]] to explicitly state whether they can be | ||
* Element types that make this action available should implement [[ElementInterface::canDelete()]] to explicitly state whether they can be | ||
* deleted by the current user. | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
|
@@ -70,7 +70,7 @@ public function setHardDelete(): void | |
*/ | ||
public function getTriggerHtml(): ?string | ||
{ | ||
// Only enable for deletable elements, per getIsDeletable() | ||
// Only enable for deletable elements, per canDelete() | ||
Craft::$app->getView()->registerJsWithVars(fn($type) => <<<JS | ||
(() => { | ||
new Craft.ElementActionTrigger({ | ||
|
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 @@ | |
/** | ||
* Delete represents a “Delete for site” element action. | ||
* | ||
* Element types that make this action available should implement [[ElementInterface::getIsDeletable()]] to explicitly state whether they can be | ||
* Element types that make this action available should implement [[ElementInterface::canDelete()]] to explicitly state whether they can be | ||
* deleted by the current user. | ||
* | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
|
@@ -41,7 +41,7 @@ class DeleteForSite extends ElementAction | |
*/ | ||
public function getTriggerHtml(): ?string | ||
{ | ||
// Only enable for deletable elements, per getIsDeletable() | ||
// Only enable for deletable elements, per canDelete() | ||
Craft::$app->getView()->registerJsWithVars(fn($type) => <<<JS | ||
(() => { | ||
new Craft.ElementActionTrigger({ | ||
|
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
Oops, something went wrong.