Commit bf48f932 authored by Sean Madsen's avatar Sean Madsen

Accept any version descriptor when publishing

This makes it possible to publish a book with something like
/admin/publish/user/en/latest
if "latest" is a descriptor for the version which points to the
"master" branch. Previously, you had to specify "master" in order to
publish. This change makes the publishing process more flexible and
intuitive.
parent 4fa71ba4
......@@ -158,6 +158,7 @@ class Language {
}
/**
* Retrieves a version object defined for this language
*
* @param string $branch
* @return \AppBundle\Model\Version The first version in $versions which
......@@ -174,4 +175,23 @@ class Language {
return $chosen;
}
/**
* Retrieves a version object defined for this language, based on a descriptor
* which can be either a branch, or a name, or an alias.
*
* @param string $descriptor
* @return \AppBundle\Model\Version The first version in $versions which
* matches the specified descriptor
*/
public function getVersionByDescriptor($descriptor) {
$chosen = NULL;
foreach($this->versions as $version) {
if (in_array($descriptor, $version->allDescriptors())) {
$chosen = $version;
break;
}
}
return $chosen;
}
}
......@@ -186,16 +186,17 @@ class Publisher {
/**
* Find the requested version within the language
*
* @param string $branchName
* @param string $versionDescriptor
*
* @return boolean TRUE if success
*/
private function initializeVersion($branchName) {
$this->version = $this->language->getVersionByBranch($branchName);
private function initializeVersion($versionDescriptor) {
$this->version
= $this->language->getVersionByDescriptor($versionDescriptor);
if (!$this->version) {
$this->addMessage('CRITICAL',
"Branch '{$branchName}' is not defined for "
. "language '{$this->language->englishName()}' within "
"Descriptor '{$versionDescriptor}' does not map to a version defined "
. "within language '{$this->language->englishName()}' for "
. "book '{$this->book->name}'.");
return FALSE;
}
......@@ -360,17 +361,19 @@ class Publisher {
/**
* Publish a book based on certain identifiers
*
* @param string $bookSlug
* @param string $languageCode
* @param string $branchName
* @param string $bookSlug The short name of the book
* @param string $languageCode An ISO 639-1 two letter language code
* @param string $versionDescriptor Can be the name of the version, the name
* of the git branch, or a name of an alias
* defined for the version
*
* @return bool TRUE if book was published, FALSE if there were errors
*/
public function publish($bookSlug, $languageCode, $branchName) {
public function publish($bookSlug, $languageCode, $versionDescriptor) {
$success =
$this->initializeBook($bookSlug) &&
$this->initializeLanguage($languageCode) &&
$this->initializeVersion($branchName) &&
$this->initializeVersion($versionDescriptor) &&
$this->initializeLocations() &&
$this->initializeRepo() &&
$this->gitCheckout() &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment