Skip to content

Commit

Permalink
Add 'file/append' action
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed May 30, 2017
1 parent 2e96767 commit cd35b77
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Core/Executor/FileExecutor.php
Expand Up @@ -8,7 +8,7 @@
class FileExecutor extends AbstractExecutor
{
protected $supportedStepTypes = array('file');
protected $supportedActions = array('load', 'save', 'copy', 'move', 'delete');
protected $supportedActions = array('load', 'save', 'copy', 'move', 'delete', 'append');

/** @var PrefixBasedResolverInterface $referenceResolver */
protected $referenceResolver;
Expand Down Expand Up @@ -93,6 +93,33 @@ protected function save($dsl, $context)
return $return;
}

/**
* @param array $dsl
* @param array $context
* @return int
* @throws \Exception
*/
protected function append($dsl, $context)
{
if (!isset($dsl['file']) || !isset($dsl['body'])) {
throw new \Exception("Can not append to file: name or body missing");
}

if (is_string($dsl['body'])) {
$contents = $this->resolveReferencesInText($dsl['body']);
} else {
throw new \Exception("Can not append to file: body tag must be a string");
}

$fileName = $this->referenceResolver->resolveReference($dsl['file']);

$return = file_put_contents($fileName, $contents, FILE_APPEND);

$this->setReferences($fileName, $dsl);

return $return;
}

/**
* @param array $dsl
* @param array $context
Expand Down
14 changes: 14 additions & 0 deletions Resources/doc/DSL/Files.yml
Expand Up @@ -26,6 +26,20 @@
attribute: attributeId # An attribute to get the value of for the reference.
# Supports: size, uid, gid, ctime, mtime, atime, body

-
type: file
mode: append
file: xxx # string. Filename including path. References will be resolved
body: "file contents" # string. References will be replaced as long as they are within square brackets
# eg. to save to a file the value of reference 'abc', write: body: "[reference:abc]"
# The list in references tells the manager to store specific values for later use by other steps in the current migration.
# NB: these are NEW VARIABLES THAT YOU ARE CREATING. They are not used in the current migration step!
references: # Optional
-
identifier: referenceId # A string used to identify the reference
attribute: attributeId # An attribute to get the value of for the reference.
# Supports: size, uid, gid, ctime, mtime, atime, body

-
type: file
mode: delete
Expand Down
6 changes: 6 additions & 0 deletions WHATSNEW.md
@@ -1,3 +1,9 @@
Version 4.0 RC-4 (unreleased)
=============================

* Added 'append' action to 'file' executor


Version 4.0 RC-3
================

Expand Down

0 comments on commit cd35b77

Please sign in to comment.