2014-04-12 14:31:31 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace PHPCensor\Plugin;
|
2014-04-12 14:31:31 +02:00
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
use PHPCensor\Builder;
|
|
|
|
use PHPCensor\Model\Build;
|
|
|
|
use PHPCensor\Plugin;
|
2014-04-12 14:31:31 +02:00
|
|
|
|
|
|
|
/**
|
2017-01-10 18:46:19 +01:00
|
|
|
* Wipe Plugin - Wipes a folder
|
|
|
|
*
|
2017-03-04 16:39:56 +01:00
|
|
|
* @author Claus Due <claus@namelesscoder.net>
|
2017-01-10 18:46:19 +01:00
|
|
|
*/
|
2016-07-11 18:00:04 +02:00
|
|
|
class Wipe extends Plugin
|
2014-04-12 14:31:31 +02:00
|
|
|
{
|
2014-05-02 15:48:40 +02:00
|
|
|
protected $directory;
|
|
|
|
|
2017-01-11 16:15:54 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function pluginName()
|
|
|
|
{
|
|
|
|
return 'wipe';
|
|
|
|
}
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
2016-07-11 18:00:04 +02:00
|
|
|
* {@inheritdoc}
|
2014-12-08 12:25:33 +01:00
|
|
|
*/
|
2016-07-22 09:05:34 +02:00
|
|
|
public function __construct(Builder $builder, Build $build, array $options = [])
|
2014-04-12 14:31:31 +02:00
|
|
|
{
|
2016-07-22 09:05:34 +02:00
|
|
|
parent::__construct($builder, $build, $options);
|
2016-07-11 18:00:04 +02:00
|
|
|
|
2016-07-22 09:05:34 +02:00
|
|
|
$path = $this->builder->buildPath;
|
|
|
|
$this->directory = isset($options['directory']) ? $this->builder->interpolate($options['directory']) : $path;
|
2014-04-12 14:31:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wipes a directory's contents
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
2016-07-22 09:05:34 +02:00
|
|
|
$build = $this->builder->buildPath;
|
2014-04-12 14:31:31 +02:00
|
|
|
|
|
|
|
if ($this->directory == $build || empty($this->directory)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (is_dir($this->directory)) {
|
2014-05-09 09:57:22 +02:00
|
|
|
$cmd = 'rm -Rf "%s"';
|
2017-02-01 16:27:47 +01:00
|
|
|
|
2016-07-22 09:05:34 +02:00
|
|
|
return $this->builder->executeCommand($cmd, $this->directory);
|
2014-04-12 14:31:31 +02:00
|
|
|
}
|
2017-02-01 16:27:47 +01:00
|
|
|
|
2015-03-16 12:05:33 +01:00
|
|
|
return true;
|
2014-04-12 14:31:31 +02:00
|
|
|
}
|
|
|
|
}
|