Commit 89ffcb5a authored by mickadoo's avatar mickadoo

68: Publish to tmp dir, copy over when complete

parent b5d66804
......@@ -186,6 +186,7 @@ class Publisher {
$version = $this->getVersion($book, $language, $versionDescriptor);
$branch = $version->branch;
$bookRepo = $language->repo;
$tmpPrefix = $book->slug . '_' . $language->code . '_' . time();
$this->showVersionInfo($book, $language, $version);
......@@ -193,16 +194,23 @@ class Publisher {
$masterRepoDir = sprintf('%s/%s/%s', $repoRoot, $book->slug, $language->code);
$this->setupLocalRepo($masterRepoDir, $bookRepo);
$tmpRepoDir = $this->makeTmpRepo($book, $language, $masterRepoDir);
$repoPrefix = 'repo_' . $tmpPrefix;
$tmpRepoDir = $this->makeTmpRepo($repoPrefix, $masterRepoDir);
$this->git->checkout($tmpRepoDir, $branch);
$this->git->pull($tmpRepoDir);
$this->addMessage('INFO', sprintf("Checked out branch '%s'", $branch));
$publishPrefix = 'publish_' . $tmpPrefix;
$tmpPublishDir = $this->makeTmpDir($publishPrefix);
$this->build($book, $language, $version, $tmpRepoDir, $tmpPublishDir);
$path = "{$book->slug}/{$language->code}/{$branch}";
$webRoot = $this->paths->getPublishPathRoot() . "/{$path}";
$this->fs->mkdir($webRoot);
$this->build($book, $language, $version, $tmpRepoDir, $webRoot);
$this->fs->copyDir($tmpPublishDir, $webRoot);
$format = "<a href='/%s'>Book published successfully</a>.";
$msg = sprintf($format, $path);
......@@ -212,7 +220,8 @@ class Publisher {
$this->setupRedirects($tmpRepoDir, $webRoot);
$this->fs->removeDir($tmpRepoDir);
// todo change publish dir to tmp dir
$this->fs->removeDir($tmpPublishDir);
// todo remove yaml file generated by publishing
}
/**
......@@ -392,19 +401,28 @@ class Publisher {
}
/**
* @param $book
* @param $language
* @param $masterRepoDir
* @param string $prefix
* @param string $masterRepoDir
*
* @return string
*/
private function makeTmpRepo($prefix, $masterRepoDir): string {
$tmpRepoDir = $this->makeTmpDir($prefix);
$this->fs->copyDir($masterRepoDir, $tmpRepoDir);
return $tmpRepoDir;
}
/**
* @param $prefix
*
* @return string
*/
private function makeTmpRepo($book, $language, $masterRepoDir): string {
private function makeTmpDir($prefix) {
$cacheDir = $this->paths->getCacheDir() . '/publishing';
$this->fs->mkdir($cacheDir);
$prefix = $book->slug . '_' . $language->code . '_' . time();
$tmpRepoDir = $cacheDir . '/' . $prefix;
$this->fs->mkdir($tmpRepoDir);
$this->fs->copyDir($masterRepoDir, $tmpRepoDir);
return $tmpRepoDir;
}
......
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