-
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #58 from getkirby/release/1.3.0
1.3.0
- Loading branch information
Showing
11 changed files
with
133 additions
and
47 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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
# OS files | ||
# os | ||
.DS_Store | ||
|
||
# Vendor files | ||
# vendor files | ||
/node_modules | ||
/vendor | ||
|
||
# Cache and temporary files | ||
/.cache | ||
/.php-cs-fixer.cache | ||
/.phpunit.result.cache | ||
# cs fixer | ||
.php-cs-fixer.cache | ||
|
||
# tests | ||
.phpunit.cache | ||
/tests/coverage | ||
/tests/*/tmp | ||
/tests/tmp |
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,79 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
use Kirby\CLI\CLI; | ||
|
||
function clean( | ||
Generator $collection, | ||
array|null $ignore = null, | ||
string|null $lang = null | ||
): void { | ||
foreach($collection as $item) { | ||
// get all fields in the content file | ||
$contentFields = $item->content($lang)->fields(); | ||
|
||
// unset all fields in the `$ignore` array | ||
foreach ($ignore as $field) { | ||
if (array_key_exists($field, $contentFields) === true) { | ||
unset($contentFields[$field]); | ||
} | ||
} | ||
|
||
// get the keys | ||
$contentFields = array_keys($contentFields); | ||
|
||
// get all field keys from blueprint | ||
$blueprintFields = array_keys($item->blueprint()->fields()); | ||
|
||
// get all field keys that are in $contentFields but not in $blueprintFields | ||
$fieldsToBeDeleted = array_diff($contentFields, $blueprintFields); | ||
|
||
// update page only if there are any fields to be deleted | ||
if (count($fieldsToBeDeleted) > 0) { | ||
|
||
// flip keys and values and set new values to null | ||
$data = array_map(fn ($value) => null, array_flip($fieldsToBeDeleted)); | ||
|
||
// try to update the page with the data | ||
try { | ||
$item->update($data, $lang); | ||
} catch (Exception $e) { | ||
throw $e->getMessage(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return [ | ||
'description' => 'Deletes all fields from page, file or user content files that are not defined in the blueprint, no matter if they contain content or not.', | ||
'command' => static function (CLI $cli): void { | ||
|
||
$cli->confirmToContinue('This will delete all fields from content files that are not defined in blueprints, no matter if they contain content or not. Are you sure?'); | ||
|
||
$kirby = $cli->kirby(); | ||
|
||
// Authenticate as almighty | ||
$kirby->impersonate('kirby'); | ||
|
||
// Define your collection | ||
$collection = $kirby->models(); | ||
|
||
// set the fields to be ignored | ||
$ignore = ['uuid', 'title', 'slug', 'template', 'sort', 'focus']; | ||
|
||
// call the script for all languages if multilang | ||
if ($kirby->multilang() === true) { | ||
$languages = $kirby->languages(); | ||
|
||
foreach ($languages as $language) { | ||
clean($collection, $ignore, $language->code()); | ||
} | ||
|
||
} else { | ||
clean($collection, $ignore); | ||
} | ||
|
||
$cli->success('The content files have been cleaned'); | ||
} | ||
]; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,32 +1,41 @@ | ||
<?xml version="1.0"?> | ||
|
||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
|
||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" | ||
beStrictAboutOutputDuringTests="true" | ||
bootstrap="tests/bootstrap.php" | ||
cacheDirectory=".phpunit.cache" | ||
colors="true" | ||
forceCoversAnnotation="true" | ||
verbose="true" | ||
controlGarbageCollector="true" | ||
displayDetailsOnIncompleteTests="true" | ||
displayDetailsOnSkippedTests="true" | ||
displayDetailsOnTestsThatTriggerDeprecations="true" | ||
displayDetailsOnTestsThatTriggerErrors="true" | ||
displayDetailsOnTestsThatTriggerNotices="true" | ||
displayDetailsOnTestsThatTriggerWarnings="true" | ||
failOnDeprecation="true" | ||
failOnEmptyTestSuite="true" | ||
failOnIncomplete="true" | ||
failOnNotice="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
stderr="true" | ||
> | ||
<coverage> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
|
||
<exclude> | ||
<directory suffix=".php">./src/Kql/Interceptors</directory> | ||
</exclude> | ||
</coverage> | ||
<source> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
</source> | ||
|
||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<testsuite name="Tests"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<php> | ||
<ini name="memory_limit" value="2048M"/> | ||
</php> | ||
|
||
<php> | ||
<ini name="memory_limit" value="2048M" /> | ||
</php> | ||
<coverage ignoreDeprecatedCodeUnits="true" /> | ||
</phpunit> |
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