Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
M2 content provisioning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TechDivision Public
M2 content provisioning
Commits
8ee63e79
Unverified
Commit
8ee63e79
authored
May 24, 2022
by
Vadim Justus
Committed by
GitHub
May 24, 2022
Browse files
Options
Downloads
Plain Diff
Merge pull request #40 from TD-ellguthe/develop
Add block reset command
parents
e65c6745
b590f29f
Branches
Branches containing commit
Tags
1.4.0
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Model/Console/BlockResetCommand.php
+160
-0
160 additions, 0 deletions
Model/Console/BlockResetCommand.php
README.md
+23
-1
23 additions, 1 deletion
README.md
etc/di.xml
+1
-0
1 addition, 0 deletions
etc/di.xml
with
184 additions
and
1 deletion
Model/Console/BlockResetCommand.php
0 → 100644
+
160
−
0
View file @
8ee63e79
<?php
/**
* Copyright (c) 2021 TechDivision GmbH <info@techdivision.com> - TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
declare
(
strict_types
=
1
);
namespace
Firegento\ContentProvisioning\Model\Console
;
use
Firegento\ContentProvisioning\Api\Data\BlockEntryInterface
;
use
Firegento\ContentProvisioning\Model\Command\ApplyBlockEntry
;
use
Firegento\ContentProvisioning\Model\Command\ApplyMediaFiles
;
use
Firegento\ContentProvisioning\Model\Query\GetBlockEntryList
;
use
Magento\Framework\Console\Cli
;
use
Symfony\Component\Console\Command\Command
;
use
Symfony\Component\Console\Input\InputInterface
;
use
Symfony\Component\Console\Input\InputOption
;
use
Symfony\Component\Console\Output\OutputInterface
;
/**
* @copyright Copyright (c) 2021 TechDivision GmbH <info@techdivision.com> - TechDivision GmbH
*
* @link https://www.techdivision.com/
* @author Team Zero <zero@techdivision.com>
*/
class
BlockResetCommand
extends
Command
{
public
const
COMMAND
=
'content-provisioning:block:reset'
;
public
const
PARAM_KEY
=
'key'
;
public
const
PARAM_IDENTIFIER
=
'identifier'
;
private
GetBlockEntryList
$getBlockEntryList
;
private
ApplyBlockEntry
$applyBlockEntry
;
private
ApplyMediaFiles
$applyMediaFiles
;
/**
* @param GetBlockEntryList $getBlockEntryList
* @param ApplyBlockEntry $applyBlockEntry
* @param ApplyMediaFiles $applyMediaFiles
*/
public
function
__construct
(
GetBlockEntryList
$getBlockEntryList
,
ApplyBlockEntry
$applyBlockEntry
,
ApplyMediaFiles
$applyMediaFiles
)
{
parent
::
__construct
();
$this
->
getBlockEntryList
=
$getBlockEntryList
;
$this
->
applyBlockEntry
=
$applyBlockEntry
;
$this
->
applyMediaFiles
=
$applyMediaFiles
;
}
/**
* Configures the current command.
*/
protected
function
configure
():
void
{
$this
->
setName
(
self
::
COMMAND
);
$this
->
setDescription
(
'Reset CMS content'
);
$this
->
addOption
(
self
::
PARAM_KEY
,
'k'
,
InputOption
::
VALUE_OPTIONAL
,
'Key'
);
$this
->
addOption
(
self
::
PARAM_IDENTIFIER
,
'i'
,
InputOption
::
VALUE_OPTIONAL
,
'Identifier'
);
parent
::
configure
();
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected
function
execute
(
InputInterface
$input
,
OutputInterface
$output
):
int
{
try
{
[
$search
,
$type
]
=
$this
->
parseParams
(
$input
);
}
catch
(
\Exception
$e
)
{
$output
->
writeln
(
'<error>'
.
$e
->
getMessage
()
.
'</error>'
.
"
\n
"
);
return
Cli
::
RETURN_FAILURE
;
}
$blockEntries
=
$this
->
getBlockEntries
(
$search
,
$type
);
$updateCount
=
0
;
if
(
empty
(
$blockEntries
))
{
$output
->
writeln
(
'<error>block entry not found for '
.
$type
.
' "'
.
$search
.
'"</error>'
.
"
\n
"
);
return
Cli
::
RETURN_FAILURE
;
}
try
{
foreach
(
$blockEntries
as
$blockEntry
)
{
$this
->
applyBlockEntry
->
execute
(
$blockEntry
);
$this
->
applyMediaFiles
->
execute
(
$blockEntry
);
$updateCount
++
;
}
}
catch
(
\Exception
$exception
)
{
$output
->
writeln
(
'<error>'
.
$exception
->
getMessage
()
.
'</error>'
.
"
\n
"
);
return
Cli
::
RETURN_FAILURE
;
}
$pluralS
=
(
$updateCount
>
1
)
?
's'
:
''
;
$output
->
writeln
(
'<info>'
.
$updateCount
.
' block'
.
$pluralS
.
' successfully updated</info>'
);
return
Cli
::
RETURN_SUCCESS
;
}
/**
* @param InputInterface $input
* @return string[]
* @throws \Exception
*/
private
function
parseParams
(
InputInterface
$input
):
array
{
$key
=
$input
->
getOption
(
self
::
PARAM_KEY
);
$identifier
=
$input
->
getOption
(
self
::
PARAM_IDENTIFIER
);
if
((
!
empty
(
$key
))
&&
(
!
empty
(
$identifier
)))
{
throw
new
\Exception
(
'Provide either "'
.
self
::
PARAM_KEY
.
'" or "'
.
self
::
PARAM_IDENTIFIER
.
'", not both!'
);
}
if
(
!
empty
(
$key
))
{
$search
=
$key
;
$type
=
self
::
PARAM_KEY
;
}
elseif
(
!
empty
(
$identifier
))
{
$search
=
$identifier
;
$type
=
self
::
PARAM_IDENTIFIER
;
}
else
{
throw
new
\Exception
(
'Provide either "'
.
self
::
PARAM_KEY
.
'" or "'
.
self
::
PARAM_IDENTIFIER
.
'"!'
);
}
return
[
$search
,
$type
];
}
/**
* @param string $search
* @param string $type
* @return BlockEntryInterface[]
*/
private
function
getBlockEntries
(
string
$search
,
string
$type
=
self
::
PARAM_KEY
):
array
{
if
(
!
in_array
(
$type
,
[
self
::
PARAM_KEY
,
self
::
PARAM_IDENTIFIER
]))
{
return
[];
}
$method
=
'get'
.
ucfirst
(
$type
);
$entries
=
[];
foreach
(
$this
->
getBlockEntryList
->
get
()
as
$blockEntry
)
{
if
(
$blockEntry
->
$method
()
===
$search
)
{
$entries
[]
=
$blockEntry
;
}
}
return
$entries
;
}
}
This diff is collapsed.
Click to expand it.
README.md
+
23
−
1
View file @
8ee63e79
...
@@ -10,7 +10,6 @@ Only the latest patch versions of the following Magento versions are covered by
...
@@ -10,7 +10,6 @@ Only the latest patch versions of the following Magento versions are covered by
| PHP | Magento 2.3 | Magento 2.4 |
| PHP | Magento 2.3 | Magento 2.4 |
|:---: |:---:|:---:|
|:---: |:---:|:---:|
| 7.3 |
[

](https://travis-ci.org/magento-hackathon/m2-content-provisioning) |
[

](https://travis-ci.org/magento-hackathon/m2-content-provisioning) |
| 7.4 | - |
[

](https://travis-ci.org/magento-hackathon/m2-content-provisioning) |
| 7.4 | - |
[

](https://travis-ci.org/magento-hackathon/m2-content-provisioning) |
## The idea behind this module
## The idea behind this module
...
@@ -168,6 +167,29 @@ vi dev/tests/integration/etc/install-config-mysql.php
...
@@ -168,6 +167,29 @@ vi dev/tests/integration/etc/install-config-mysql.php
php vendor/bin/phpunit
-c
$(
pwd
)
/vendor/firegento/magento2-content-provisioning/Test/Integration/phpunit.xml
php vendor/bin/phpunit
-c
$(
pwd
)
/vendor/firegento/magento2-content-provisioning/Test/Integration/phpunit.xml
```
```
## Console Commands
```
shell
# reset a CMS block (all localizations) by its key
bin/magento content-provisioning:block:reset
--key
"myKey"
bin/magento content-provisioning:block:reset
-k
"myKey"
# reset a CMS blocks by its identifier
bin/magento content-provisioning:block:reset
--identifier
"myIdentifier"
bin/magento content-provisioning:block:reset
--i
"myIdentifier"
# add a CMS block by key
bin/magento content-provisioning:block:apply
"myKey"
# add a CMS page by key
bin/magento content-provisioning:page:apply
"myKey"
# list all configured CMS block entries
bin/magento content-provisioning:block:list
# list all configured CMS page entries
bin/magento content-provisioning:page:list
```
## Issues and planned features
## Issues and planned features
See issues to see what's planed next: https://github.com/magento-hackathon/m2-content-provisioning/issues
See issues to see what's planed next: https://github.com/magento-hackathon/m2-content-provisioning/issues
...
...
This diff is collapsed.
Click to expand it.
etc/di.xml
+
1
−
0
View file @
8ee63e79
...
@@ -87,6 +87,7 @@
...
@@ -87,6 +87,7 @@
<item
name=
"contentProvisioning.BlockList"
xsi:type=
"object"
>
Firegento\ContentProvisioning\Model\Console\BlockListCommand
</item>
<item
name=
"contentProvisioning.BlockList"
xsi:type=
"object"
>
Firegento\ContentProvisioning\Model\Console\BlockListCommand
</item>
<item
name=
"contentProvisioning.PageAdd"
xsi:type=
"object"
>
Firegento\ContentProvisioning\Model\Console\AddPageCommand
</item>
<item
name=
"contentProvisioning.PageAdd"
xsi:type=
"object"
>
Firegento\ContentProvisioning\Model\Console\AddPageCommand
</item>
<item
name=
"contentProvisioning.BlockAdd"
xsi:type=
"object"
>
Firegento\ContentProvisioning\Model\Console\AddBlockCommand
</item>
<item
name=
"contentProvisioning.BlockAdd"
xsi:type=
"object"
>
Firegento\ContentProvisioning\Model\Console\AddBlockCommand
</item>
<item
name=
"contentProvisioning.BlockReset"
xsi:type=
"object"
>
Firegento\ContentProvisioning\Model\Console\BlockResetCommand
</item>
</argument>
</argument>
</arguments>
</arguments>
</type>
</type>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment