Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Fix code style issues.
  Fix loadCommands trait.
  Update documentation.
  Remove drupal specific settings. Move them to robo-digipolis-drupal8.
  Fix indentation.
  Fix code style issues.
  Fix code style issues.
  Fix code style issues.
  Improve output.
  • Loading branch information
Jelle-S committed Mar 9, 2017
2 parents c93a0b7 + 1638d80 commit 6c3888b
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ engines:
config:
languages:
php:
mass_threshold: 50
mass_threshold: 80
fixme:
enabled: true
markdownlint:
Expand Down
18 changes: 2 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ directory of the local filesystem.
Path to a PHP file containing database config as documented at
<https://github.com/backup-manager/backup-manager>. Defaults to a database with
the name of the current working directory as database name, on `localhost` port
`3306`, user `root` and an empty password. If the `--drupal` option is given and
this option is skipped, the database config will be parsed from Drupal's
`settings.php`.
`3306`, user `root` and an empty password.

##### --compression, -c

Expand All @@ -301,11 +299,6 @@ current working directory.

The destination type (e.g. `local`, `dropbox`, `ftp`). Defaults to `local`.

##### --drupal

Wether or not to parse the database config from Drupal's `settings.php`. See
the documentation for `--database-config`.

### digipolis:database-restore

`vendor/bin/robo digipolis:database-restore [DATABASE] [OPTIONS]`
Expand All @@ -330,9 +323,7 @@ directory of the local filesystem.
Path to a PHP file containing database config as documented at
<https://github.com/backup-manager/backup-manager>. Defaults to a database with
the name of the current working directory as database name, on `localhost` port
`3306`, user `root` and an empty password. If the `--drupal` option is given and
this option is skipped, the database config will be parsed from Drupal's
`settings.php`.
`3306`, user `root` and an empty password.

##### --compression, -c

Expand All @@ -347,11 +338,6 @@ directory.

The source type (e.g. `local`, `dropbox`, `ftp`). Defaults to `local`.

##### --drupal

Wether or not to parse the database config from Drupal's `settings.php`. See
the documentation for `--database-config`.

### digipolis:push-package

`vendor/bin/robo digipolis:push-package USER HOST PACKAGE [DESTINATION] [OPTIONS]`
Expand Down
1 change: 0 additions & 1 deletion src/BackupManager/Compressors/TarCompressor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function getDecompressCommandLine($outputPath)
. ' --directory=' . escapeshellarg(dirname($outputPath))
. ' --transform=' . escapeshellarg('s,.*,' . $this->getDecompressedPath(basename($outputPath)) . ',')
. ' && rm -rf ' . escapeshellarg($outputPath);

}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/BackupManager/Databases/MysqlDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function getDumpCommandLine($outputPath)
*/
public function getRestoreCommandLine($inputPath)
{
return sprintf('mysql --host=%s --port=%s --user=%s --password=%s %s -e "source %s"',
return sprintf(
'mysql --host=%s --port=%s --user=%s --password=%s %s -e "source %s"',
escapeshellarg($this->config['host']),
escapeshellarg($this->config['port']),
escapeshellarg($this->config['user']),
Expand Down
1 change: 1 addition & 0 deletions src/ClearOpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function run()
$adapter = new \CacheTool\Adapter\FastCGI($this->host);
break;
}
$this->printTaskInfo(sprintf('Resetting opcache for %s.', $this->environment));
$cachetool = \CacheTool\CacheTool::factory($adapter);
$cachetool->opcache_reset();
return Result::success($this);
Expand Down
4 changes: 1 addition & 3 deletions src/Commands/DatabaseBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ public function digipolisDatabaseBackup($database = 'default', $opts = [
'compression|c' => 'gzip',
'destination|d' => null,
'destination-type|dtype' => 'local',
'drupal' => false,
])
{
if (is_callable([$this, 'readProperties']))
{
if (is_callable([$this, 'readProperties'])) {
$this->readProperties();
}
$destination = is_null($opts['destination'])
Expand Down
4 changes: 1 addition & 3 deletions src/Commands/DatabaseRestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ public function digipolisDatabaseRestore($database = 'default', $opts = [
'compression|c' => 'gzip',
'source|s' => null,
'source-type|stype' => 'local',
'drupal' => false,
])
{
if (is_callable([$this, 'readProperties']))
{
if (is_callable([$this, 'readProperties'])) {
$this->readProperties();
}
$source = is_null($opts['source'])
Expand Down
1 change: 0 additions & 1 deletion src/Commands/loadCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ trait loadCommands
use DatabaseBackup, DatabaseRestore {
DatabaseBackup::defaultFileSystemConfig insteadof DatabaseRestore;
DatabaseBackup::defaultDbConfig insteadof DatabaseRestore;
DatabaseBackup::parseDrupalDbConfig insteadof DatabaseRestore;
DatabaseBackup::createDbTask insteadof DatabaseRestore;
}
use PushPackage;
Expand Down
54 changes: 3 additions & 51 deletions src/Common/DatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ protected function defaultFileSystemConfig()
];
}

protected function defaultDbConfig($drupal = false)
protected function defaultDbConfig()
{
$dbConfig = [
return [
'default' => [
'type' => 'mysql',
'host' => 'localhost',
Expand All @@ -29,54 +29,6 @@ protected function defaultDbConfig($drupal = false)
'database' => dirname(realpath(getcwd())),
],
];
return $drupal
? $this->parseDrupalDbConfig()
: $dbConfig;
}

protected function parseDrupalDbConfig()
{
$webDir = $this->getConfig()->get('digipolis.root.web', false);
if (!$webDir) {
return false;
}

$finder = new \Symfony\Component\Finder\Finder();
$finder->in($webDir . '/sites')->files()->name('settings.php');
foreach ($finder as $settingsFile) {
$site_path = null;
$app_root = null;
include_once $settingsFile->getRealpath();
break;
}
if (!isset($databases['default']['default'])) {
return false;
}
$config = $databases['default']['default'];
return [
'default' => [
'type' => $config['driver'],
'host' => $config['host'],
'port' => isset($config['port']) ? $config['port'] : '3306',
'user' => $config['username'],
'pass' => $config['password'],
'database' => $config['database'],
'structureTables' => [
'batch',
'cache',
'cache_*',
'*_cache',
'*_cache_*',
'flood',
'search_dataset',
'search_index',
'search_total',
'semaphore',
'sessions',
'watchdog',
],
]
];
}

/**
Expand All @@ -98,7 +50,7 @@ protected function createDbTask($task, $database, $opts)
: $this->defaultFileSystemConfig();
$dbConfig = $opts['database-config']
?
: $this->defaultDbConfig($opts['drupal']);
: $this->defaultDbConfig();

return $this->{$task}($filesystemConfig, $dbConfig)
->compression($opts['compression'])
Expand Down
16 changes: 14 additions & 2 deletions src/DatabaseBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,23 @@ public function run()
* The backup manager
* @var \DigipolisGent\Robo\Task\Deploy\BackupManager\Adapter\BackupManagerAdapterInterface
*/
$manager = call_user_func([$this->backupManagerFactory, 'create'], $this->filesystemConfig, $this->dbConfig);
$manager = call_user_func(
[$this->backupManagerFactory, 'create'],
$this->filesystemConfig,
$this->dbConfig
);
if (empty($this->destinations)) {
$this->destination(getcwd());
}
$manager->makeBackup()->run($this->database, $this->destinations, $this->compression);
$this->printTaskInfo(sprintf(
'Creating database backup with %s compression.',
$this->compression
));
$manager->makeBackup()->run(
$this->database,
$this->destinations,
$this->compression
);
} catch (\Exception $e) {
return Result::fromException($this, $e);
}
Expand Down
22 changes: 20 additions & 2 deletions src/DatabaseRestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,29 @@ public function run()
* The backup manager
* @var \DigipolisGent\Robo\Task\Deploy\BackupManager\Adapter\BackupManagerAdapterInterface
*/
$manager = call_user_func([$this->backupManagerFactory, 'create'], $this->filesystemConfig, $this->dbConfig);
$manager = call_user_func(
[$this->backupManagerFactory, 'create'],
$this->filesystemConfig,
$this->dbConfig
);
if (!isset($this->sourcePath)) {
$this->source(getcwd());
}
$manager->makeRestore()->run($this->sourceType, $this->sourcePath, $this->database, $this->compression);
$this->printTaskInfo(
sprintf(
'Restoring %s backup from %s to database %s using %s compression.',
$this->sourceType,
$this->sourcePath,
$this->database,
$this->compression
)
);
$manager->makeRestore()->run(
$this->sourceType,
$this->sourcePath,
$this->database,
$this->compression
);
} catch (\Exception $e) {
return Result::fromException($this, $e);
}
Expand Down
60 changes: 39 additions & 21 deletions src/PartialCleanDirs.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ public function run()
try {
foreach ($this->dirs as $dir => $keep) {
if ($dir) {
$this->printTaskInfo(
sprintf(
'Cleaning directory %s while keeping %d items.',
$dir,
$keep
)
);
$this->cleanDir($dir, $keep);
}
}
Expand All @@ -216,6 +223,38 @@ protected function cleanDir($dir, $keep)
$finder = clone $this->finder;
$finder->in($dir);
$finder->depth(0);
$this->doSort($finder);
$items = iterator_to_array($finder->getIterator());
if ($keep) {
array_splice($items, -$keep);
}
while ($items) {
$item = reset($items);
try {
$this->fs->chmod($item, 0777, 0000, true);
} catch (IOException $e) {
// If chmod didn't work and the exception contains a path, try
// to remove anyway.
$path = $e->getPath();
if ($path && realpath($path) !== realpath($item)) {
$this->fs->remove($path);
continue;
}

}
$this->fs->remove($item);
array_shift($items);
}
}

/**
* Sort the finder.
*
* @param Finder $finder
* The finder to sort.
*/
protected function doSort(Finder $finder)
{
switch ($this->sort) {
case static::SORT_NAME:
$finder->sortByName();
Expand All @@ -241,26 +280,5 @@ protected function cleanDir($dir, $keep)
$finder->sort($this->sort);
break;
}
$items = iterator_to_array($finder->getIterator());
if ($keep) {
array_splice($items, -$keep);
}
while ($items) {
$item = reset($items);
try {
$this->fs->chmod($item, 0777, 0000, true);
} catch (IOException $e) {
// If chmod didn't work and the exception contains a path, try
// to remove anyway.
$path = $e->getPath();
if ($path && realpath($path) !== realpath($item)) {
$this->fs->remove($path);
continue;
}

}
$this->fs->remove($item);
array_shift($items);
}
}
}
Loading

0 comments on commit 6c3888b

Please sign in to comment.