Skip to content

Commit

Permalink
Merge branch 'v0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dale42 committed May 4, 2020
2 parents 2728856 + 8dd0c4e commit 170c691
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 76 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Change Log

### Version 0.2.0 (Sunday May 3, 2020)

* Add CHANGELOG.md file
* Small README.md update
* Set build signature algorithm to SHA512
* Remove _init_ command and automatically creat configuration directory
* Refactor _site_ to use $this->datastore property
* Improve _site list_ output formatting
* Update Datastore constructor docblock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Robo Site Sync
# Site Sync

A Robo based utility designed to synchronize website content for MySQL based websites such as Drupal and WordPress. It's intended use is keeping local and development websites up-to-date with the live website.

Expand Down
6 changes: 4 additions & 2 deletions build.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
'phpdoc.xml',
'phpunit.xml.dist',
'README.md',
'CHANGELOG.md',
'.git',
'.idea',
'build.php'
'build.php',
'site-sync.phar'
];

$filter = function ($file, $key, $iterator) use ($exclude) {
Expand All @@ -40,7 +42,7 @@
);

$phar = new Phar("sitesync.phar");
$phar->setSignatureAlgorithm(\Phar::SHA1);
$phar->setSignatureAlgorithm(\Phar::SHA512);
$phar->startBuffering();
$phar->buildFromIterator($iterator, $dir);
//default executable
Expand Down
36 changes: 18 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions init.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

const APP_NAME = "RoboSiteSync";
const APP_VERSION = '0.1.0';
const APP_VERSION = '0.2.0';

// If we're running from phar load the phar autoload file.
$pharPath = \Phar::running(true);
Expand All @@ -20,7 +20,6 @@
\RoboSiteSync\Commands\SiteCmd::class,
\RoboSiteSync\Commands\PairCmd::class,
\RoboSiteSync\Commands\SyncCmd::class,
\RoboSiteSync\Commands\InitCmd::class,
];

$statusCode = (new \Robo\Runner($commandClasses))
Expand Down
35 changes: 0 additions & 35 deletions src/Commands/InitCmd.php

This file was deleted.

16 changes: 7 additions & 9 deletions src/Commands/SiteCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public function site( $action = '', $sitename = '', $opts = ['prompt|p' => false
/*
* Validation
*/
if (!Datastore::exists()) {
$this->say("No configuration directory. Please use init to create.");
return;
}
if ( empty($action) ) {
$this->say('Please specific an action: ' . implode(' | ', $this->validActions));
return;
Expand Down Expand Up @@ -65,17 +61,19 @@ public function site( $action = '', $sitename = '', $opts = ['prompt|p' => false
}

protected function siteList($sitename, $opts) {
$datastore = new Datastore();
if ($sitename == '') {
$output = array_reduce($datastore->getSiteList(),
function($carry, $item) {
return $carry .= "{$item->name} ({$item->description})\n";
$siteList = $this->datastore->getSiteList();
$maxNameLength = max( array_map( 'strlen', array_keys( $siteList ) ) );
$output = array_reduce(
$this->datastore->getSiteList(),
function($carry, $item) use ( $maxNameLength ) {
return $carry .= sprintf(" %-{$maxNameLength}s %s\n", $item->name, $item->description);
}, "Site List:\n"
);
$this->say($output);
}
else {
$site = $datastore->getSite($sitename);
$site = $this->datastore->getSite($sitename);
$output = (is_null($site)) ? "$site does not exist" : $site->toPrint();
$this->say($output);
}
Expand Down
52 changes: 43 additions & 9 deletions src/Entity/Datastore.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace RoboSiteSync\Entity;

use Robo\Exception\TaskException;
use Robo\ResultData;
use RoboSiteSync\Defaults;
use RoboSiteSync\Utilities;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -42,12 +44,45 @@ public static function exists( $directory = NULL ) {
);
}

public static function addDatastore( $directory = NULL ) {
if ( Datastore::exists() ) {
return new ResultData( ResultData::EXITCODE_OK, "Configuration directory exists" );
}

if ( is_null( $directory ) ) {
$directory = Defaults::getInstance()->getConfigDir();
}

// Suppress the error handler with our own to grab the error message.
$errorMessage = '';
set_error_handler(
function ($errno, $errstr, $errfile, $errline) use (&$errorMessage) {
$errorMessage = $errstr;
return TRUE;
},
E_ALL | E_STRICT
);

// Create the configuration directory.
if ( @mkdir( $directory ) ) {
$result = new ResultData( ResultData::EXITCODE_OK, "Configuration directory: {$directory}, created" );
}
else {
$result = new ResultData( ResultData::EXITCODE_ERROR, "Could not create configuration directory: $errorMessage" );
}

// Restore the previous error handler.
restore_error_handler();

return $result;
}

/**
* DataStore constructor.
* Datastore constructor.
*
* @param null $directory
*
* @throws \Exception
* @throws \Robo\Exception\TaskException
*/
public function __construct( $directory = NULL ) {
if ( is_null( $directory ) ) {
Expand All @@ -56,13 +91,12 @@ public function __construct( $directory = NULL ) {
else {
$this->directory = $directory;
}
if (
! file_exists($this->directory)
|| ! is_dir($this->directory)
|| ! is_readable($this->directory)
|| ! is_writeable($this->directory)
) {
throw new \Exception("Datastore is unavailable.");

if ( ! self::exists( $directory ) ) {
$result = self::addDatastore( $directory );
if ( ! $result->wasSuccessful() ) {
throw new TaskException( $this, $result->getMessage() );
}
}
}

Expand Down

0 comments on commit 170c691

Please sign in to comment.