diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8f68a11 --- /dev/null +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index a128f2c..cf979d6 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/build.php b/build.php index b15113d..95e3d14 100644 --- a/build.php +++ b/build.php @@ -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) { @@ -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 diff --git a/composer.lock b/composer.lock index f81ac0b..dfa8773 100644 --- a/composer.lock +++ b/composer.lock @@ -748,7 +748,7 @@ }, { "name": "symfony/console", - "version": "v4.4.7", + "version": "v4.4.8", "source": { "type": "git", "url": "https://github.com/symfony/console.git", @@ -824,7 +824,7 @@ }, { "name": "symfony/event-dispatcher", - "version": "v4.4.7", + "version": "v4.4.8", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", @@ -952,16 +952,16 @@ }, { "name": "symfony/filesystem", - "version": "v4.4.7", + "version": "v4.4.8", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "fe297193bf2e6866ed900ed2d5869362768df6a7" + "reference": "a3ebf3bfd8a98a147c010a568add5a8aa4edea0f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/fe297193bf2e6866ed900ed2d5869362768df6a7", - "reference": "fe297193bf2e6866ed900ed2d5869362768df6a7", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/a3ebf3bfd8a98a147c010a568add5a8aa4edea0f", + "reference": "a3ebf3bfd8a98a147c010a568add5a8aa4edea0f", "shasum": "" }, "require": { @@ -998,11 +998,11 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2020-03-27T16:54:36+00:00" + "time": "2020-04-12T14:39:55+00:00" }, { "name": "symfony/finder", - "version": "v4.4.7", + "version": "v4.4.8", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -1226,16 +1226,16 @@ }, { "name": "symfony/process", - "version": "v4.4.7", + "version": "v4.4.8", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "3e40e87a20eaf83a1db825e1fa5097ae89042db3" + "reference": "4b6a9a4013baa65d409153cbb5a895bf093dc7f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/3e40e87a20eaf83a1db825e1fa5097ae89042db3", - "reference": "3e40e87a20eaf83a1db825e1fa5097ae89042db3", + "url": "https://api.github.com/repos/symfony/process/zipball/4b6a9a4013baa65d409153cbb5a895bf093dc7f4", + "reference": "4b6a9a4013baa65d409153cbb5a895bf093dc7f4", "shasum": "" }, "require": { @@ -1271,7 +1271,7 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2020-03-27T16:54:36+00:00" + "time": "2020-04-15T15:56:18+00:00" }, { "name": "symfony/service-contracts", @@ -1333,16 +1333,16 @@ }, { "name": "symfony/yaml", - "version": "v4.4.7", + "version": "v4.4.8", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "ef166890d821518106da3560086bfcbeb4fadfec" + "reference": "b385dce1c0e9f839b384af90188638819433e252" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/ef166890d821518106da3560086bfcbeb4fadfec", - "reference": "ef166890d821518106da3560086bfcbeb4fadfec", + "url": "https://api.github.com/repos/symfony/yaml/zipball/b385dce1c0e9f839b384af90188638819433e252", + "reference": "b385dce1c0e9f839b384af90188638819433e252", "shasum": "" }, "require": { @@ -1388,7 +1388,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2020-03-30T11:41:10+00:00" + "time": "2020-04-28T17:55:16+00:00" } ], "packages-dev": [], diff --git a/init.php b/init.php index 470a56f..1b2e232 100755 --- a/init.php +++ b/init.php @@ -1,7 +1,7 @@ say("A configuration directory exists. No action taken."); - return; - } - - $configDir = Defaults::getInstance()->getConfigDir(); - $this->say("The directory {$configDir} will be created."); - $answer = $this->ask("Create [y/n]?"); - if (strtolower($answer) == 'y') { - $status = mkdir(Defaults::getInstance()->getConfigDir()); - $message = ($status) ? 'Directory created' : 'Could not create directory'; - $this->say($message); - } - else { - $this->say('Directory not created'); - } - } - -} \ No newline at end of file diff --git a/src/Commands/SiteCmd.php b/src/Commands/SiteCmd.php index 35ce3bf..0c3c7c6 100644 --- a/src/Commands/SiteCmd.php +++ b/src/Commands/SiteCmd.php @@ -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; @@ -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); } diff --git a/src/Entity/Datastore.php b/src/Entity/Datastore.php index 4d97084..123d32f 100644 --- a/src/Entity/Datastore.php +++ b/src/Entity/Datastore.php @@ -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; @@ -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 ) ) { @@ -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() ); + } } }