summaryrefslogtreecommitdiff
path: root/src/CopyModule.php
blob: 1f0b5c32218cf269b9ff35cd5372add234c2e45e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

namespace PHPIAC\Modules;

use PHPIAC\Connection;
use PHPIAC\Module\Module;
use PHPIAC\Modules\Support\HandlesFiles;
use PHPIAC\Modules\Support\HasPermissions;

class CopyModule extends Module
{
    use HasPermissions, HandlesFiles;

    protected string $src;
    protected string $dest;

    protected bool $force = false;
    protected bool $remoteSrc = false;

    /**
     * @inheritDoc
     */
    public function __construct(array $config)
    {
        parent::__construct($config);
    }

    /**
     * @inheritDoc
     */
    public function checkState(): bool
    {
        if ($this->force) {
            return false;
        }

        return $this->fileExists($this->dest);
    }

    /**
     * @inheritDoc
     */
    public function execute(): void
    {
        if ($this->remoteSrc) {
            Connection::exec("sudo cp -r $this->src $this->dest");
        }
        else {
            Connection::put($this->dest, $this->src);
        }

        Connection::exec($this->getPermissions($this->dest));
    }
}