Skip to content

Commit 847dc45

Browse files
committed
#91 - Support 'directory' as an archive type with rsync as the overwrite method
1 parent de669a6 commit 847dc45

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/Configuration/ConfigurationDefaults.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function __construct(&$settings) {
123123
"flatten" => 1,
124124
),
125125
),
126-
'pdf->(zip/png)' => array(
126+
'pdf->(zip/png|directory/png)' => array(
127127
'imagemagick:default' => array(
128128
'#engine' => 'Convert\\ImageMagick',
129129
"colorspace" => "sRGB",

src/Engine/Convert/ImageMagick.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ImageMagick extends EngineBase {
4848
);
4949

5050
public function convertFile($source, $destination) {
51-
if (preg_match('@zip/(?<ext>.*)$@s', $this->conversion[1], $arr)) {
51+
if (preg_match('@(?:zip|directory)/(?<ext>.*)$@s', $this->conversion[1], $arr)) {
5252
// Create a temp directory and convert the images.
5353
$ext = $arr['ext'];
5454
$imageArchive = new Archive($this);

src/Engine/Helper/Archive.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,26 @@ public function save($destination) {
5959
Shell::arg($temp, Shell::SHELL_ARG_BASIC),
6060
Shell::arg('.', Shell::SHELL_SAFE),
6161
);
62-
echo $this->engine->shell($cmd);
62+
$this->engine->shell($cmd);
6363
rename($temp, $destination);
6464
break;
6565

66+
case 'directory':
67+
if (!is_dir($destination)) {
68+
mkdir($destination);
69+
if (!is_dir($destination)) {
70+
throw new \ErrorException("Unable to create the destination directory.");
71+
}
72+
}
73+
$cmd = array(
74+
$this->engine->shellWhich('rsync'),
75+
Shell::arg('a', Shell::SHELL_ARG_BOOL_SGL, TRUE),
76+
Shell::arg(rtrim($this->getTempDirectory(), '/') . '/', Shell::SHELL_ARG_BASIC),
77+
Shell::arg(rtrim($destination, '/') . '/', Shell::SHELL_ARG_BASIC),
78+
);
79+
$this->engine->shell($cmd);
80+
break;
81+
6682
default:
6783
throw new \InvalidArgumentException("Invalid archive format spec: $ext");
6884
}

0 commit comments

Comments
 (0)