Skip to content

Commit 92b58b2

Browse files
committed
3.0-alpha1
1 parent 6cbe4eb commit 92b58b2

File tree

5 files changed

+211
-29
lines changed

5 files changed

+211
-29
lines changed

src/Commands/D9ify/ProcessCommand.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public function process($sourceSite, $destinationSite = null, $options = [])
121121
'drupal9',
122122
['org' => null]
123123
);
124+
$destinationSiteInfoCommand = $this->getContainer()->get(InfoCommand::class);
124125
$destinationSiteInfo = $destinationSiteInfoCommand->info($destinationSite)->getArrayCopy();
125126
$this->getContainer()->add('destinationSiteModel', Site::class)
126127
->addArgument($destinationSiteInfo);
@@ -157,21 +158,20 @@ public function process($sourceSite, $destinationSite = null, $options = [])
157158
"*************************************************************",
158159
]);
159160

160-
\Kint::dump($this->sites());
161-
exit();
161+
162162

163163
$this->copyRepositoriesFromSource();
164-
$this->updateDestModulesAndThemesFromSource($output);
165-
$this->updateDestEsLibrariesFromSource($output);
166-
$this->writeComposer($output);
167-
$this->destinationComposerInstall($output);
168-
$this->copyCustomCode($output);
169-
$this->copyConfigFiles($output);
170-
$this->downloadDatabase($output);
171-
$this->downloadSourceSiteFilesDirectory($output);
164+
$this->updateDestModulesAndThemesFromSource();
165+
$this->updateDestEsLibrariesFromSource();
166+
$this->writeComposer();
167+
$this->destinationComposerInstall();
168+
$this->copyCustomCode();
169+
$this->copyConfigFiles();
170+
$this->downloadDatabase();
171+
$this->downloadSourceSiteFilesDirectory();
172172
} catch (D9ifyExceptionBase $d9ifyException) {
173173
// TODO: Composer install exception help text
174-
$io->writeln((string)$d9ifyException);
174+
$this->output()->writeln((string)$d9ifyException);
175175
} catch (\Exception $e) {
176176
// TODO: General help text and how to restart the process
177177
$this->output()->writeln("Script ended in Exception state. " . $e->getMessage());
@@ -213,9 +213,9 @@ protected function setSourceDirectory(Directory $sourceDirectory): void
213213
*
214214
* @param \Symfony\Component\Console\Output\OutputInterface $output
215215
*/
216-
protected function copyRepositoriesFromSource(OutputInterface $output)
216+
protected function copyRepositoriesFromSource()
217217
{
218-
$output->writeln([
218+
$this->output()->writeln([
219219
"===> Ensuring source and destination folders exist.",
220220
PHP_EOL,
221221
"*********************************************************************",
@@ -224,12 +224,13 @@ protected function copyRepositoriesFromSource(OutputInterface $output)
224224
"*********************************************************************",
225225
PHP_EOL,
226226
]);
227-
$this->getSourceDirectory()->ensure(false);
228-
$this->getDestinationDirectory()->ensure(true);
227+
$this->getSourceDirectory()->ensureLocalCopyOfRepo(false);
228+
$this->getDestinationDirectory()->ensureLocalCopyOfRepo(true);
229229
$this->destinationDirectory->getComposerObject()->setRepositories(
230230
$this->sourceDirectory->getComposerObject()->getOriginal()['repositories'] ?? []
231231
);
232-
$output->writeln([
232+
exit();
233+
$this->output()->writeln([
233234
"*********************************************************************",
234235
sprintf("Source Folder: %s", $this->getSourceDirectory()->getClonePath()),
235236
sprintf("Destination Folder: %s", $this->getDestinationDirectory()->getClonePath()),

src/Helpers/Site/Directory.php

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use League\Container\ContainerAwareInterface;
66
use League\Container\ContainerAwareTrait;
7+
use Pantheon\Terminus\Exceptions\TerminusException;
8+
use Pantheon\Terminus\Exceptions\TerminusNotFoundException;
79
use Pantheon\Terminus\Helpers\Composer\ComposerFile;
810
use Pantheon\Terminus\Exceptions\ComposerInstallException;
911
use Pantheon\Terminus\Helpers\Traits\CommandExecutorTrait;
@@ -30,6 +32,9 @@ class Directory implements ContainerAwareInterface, IOAwareInterface, SiteAwareI
3032
use IO;
3133
use SiteAwareTrait;
3234

35+
/**
36+
* @var
37+
*/
3338
protected $site;
3439

3540
/**
@@ -51,10 +56,7 @@ class Directory implements ContainerAwareInterface, IOAwareInterface, SiteAwareI
5156
*/
5257
public function __construct($site)
5358
{
54-
if (is_string($site)) {
55-
$site = $this->getSite($site);
56-
}
57-
$this->site = $site;
59+
$this->setSource($site);
5860
}
5961

6062
/**
@@ -77,9 +79,9 @@ public static function delTree($dir): bool
7779
/**
7880
* @throws \Exception
7981
*/
80-
public function ensure(bool $create = false)
82+
public function ensureLocalCopyOfRepo(bool $create = false)
8183
{
82-
$valid = $this->getSource()->valid();
84+
$valid = $this->getSource()->valid() ?? false;
8385
if ($valid === false) {
8486
// if site doesn't exist
8587
if ($create === true) {
@@ -91,11 +93,11 @@ public function ensure(bool $create = false)
9193
}
9294
$this->clonePath = new \SplFileInfo(
9395
$this->getDefaultClonePathBase() .
94-
DIRECTORY_SEPARATOR . $this->getSource()->getSiteInfo()->getName()
96+
DIRECTORY_SEPARATOR . $this->getSource()->getName()
9597
);
9698
if (!$this->clonePath->isDir()) {
9799
// -oStrictHostKeyChecking=no
98-
$this->getSource()->cloneFiles($this->getOutput());
100+
$this->getSource()->cloneLocalCopy();
99101
}
100102

101103
$this->setComposerFile();
@@ -184,12 +186,12 @@ public function install()
184186
{
185187
is_file($this->clonePath . "/composer.lock") ?
186188
unlink($this->clonePath . "/composer.lock") : [];
187-
$this->execute("rm -Rf %s && cd %s && composer upgrade --with-dependencies", [
189+
$result = $this->execute("rm -Rf %s && cd %s && composer upgrade --with-dependencies", [
188190
$this->clonePath . "/vendor",
189191
$this->clonePath
190192
]);
191193
if ($this->execResult[0] !== 0) {
192-
throw new ComposerInstallException($result, $output);
194+
throw new ComposerInstallException($result, $this->output());
193195
}
194196
return $result;
195197
}
@@ -239,10 +241,13 @@ public function ensureCustomCodeFoldersExist(InputInterface $input, OutputInterf
239241
}
240242
}
241243

244+
/**
245+
* @return string
246+
*/
242247
public function getDefaultClonePathBase()
243248
{
244249
// Get path resoltion from default composer file directory
245-
return dirname(\Composer\Factory::getComposerFile()) . "/local-copies";
250+
return $_SERVER['HOME'] . "/pantheon-local-copies";
246251
}
247252

248253
/**
@@ -271,8 +276,38 @@ public function ensurePantheonYamlValues(InputInterface $input, OutputInterface
271276
yaml_emit_file($yamlFile, $pantheonYaml);
272277
}
273278

274-
public function getInfo() : Site
279+
/**
280+
* @return \Pantheon\Terminus\Models\Site|null
281+
*/
282+
public function getSource(): ? Site
283+
{
284+
return $this->site ?? null;
285+
}
286+
287+
288+
/**
289+
* @param string|Site $site
290+
*/
291+
public function setSource($site)
275292
{
276-
return $this->getSite($this->siteID);
293+
if (is_string($site)) {
294+
$this->site = $this->getSite($site);
295+
}
296+
if ($site instanceof Site) {
297+
$this->site = $site;
298+
}
299+
if (is_object($site)) {
300+
$site = (array)$site;
301+
}
302+
if (is_array($site) && isset($site['id'])) {
303+
$this->site = $this->getSite($site['id']);
304+
}
305+
if (is_array($site) && isset($site['site'])) {
306+
$this->site = $site['site'];
307+
}
308+
if (!$this->site instanceof Site) {
309+
\Kint::dump($site);
310+
throw new TerminusNotFoundException("Site not found: ");
311+
}
277312
}
278313
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Pantheon\D9ify\Site\Sources;
4+
5+
use Pantheon\D9ify\Site\InfoInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
8+
/**
9+
* Interface SiteSourceInterface
10+
*
11+
* @package D9ify\Site\Sources
12+
*/
13+
interface SiteSourceInterface
14+
{
15+
16+
17+
/**
18+
* @return bool
19+
*/
20+
public function valid(): bool;
21+
22+
/**
23+
* @param \D9ify\Site\Sources\OutputInterface $output
24+
*
25+
* @return bool
26+
*/
27+
public function cloneFiles(OutputInterface $output): bool;
28+
29+
/**
30+
* @return \D9ify\Site\InfoInterface
31+
*/
32+
public function getSiteInfo(): InfoInterface;
33+
34+
/**
35+
* @return array
36+
*/
37+
public function getConnectionInfo(): array;
38+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
namespace Pantheon\D9ify\Site\Sources;
4+
5+
use CzProject\GitPhp\GitRepository;
6+
use Pantheon\D9ify\Traits\CommandExecutorTrait;
7+
use Pantheon\D9ify\Traits\DefaultClonePathTrait;
8+
use Pantheon\D9ify\Traits\SiteInfoTrait;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
/**
12+
* Class Terminus
13+
* @package D9ify\Site\Sources
14+
*/
15+
class Terminus implements SiteSourceInterface
16+
{
17+
18+
use CommandExecutorTrait;
19+
use SiteInfoTrait;
20+
use DefaultClonePathTrait;
21+
22+
/**
23+
* @var string
24+
*/
25+
protected string $siteID;
26+
/**
27+
* @var string|mixed
28+
*/
29+
protected string $referenceEnvironment;
30+
31+
/**
32+
* Terminus constructor.
33+
* @param $siteID
34+
* @param string $referenceEnvironment
35+
*/
36+
public function __construct($siteID, $referenceEnvironment = "live")
37+
{
38+
$this->setSiteInfoFromSiteId($siteID);
39+
$this->referenceEnvironment = $referenceEnvironment;
40+
}
41+
42+
/**
43+
* @return bool
44+
*/
45+
public function valid(): bool
46+
{
47+
return $this->getSiteInfo()->valid();
48+
}
49+
50+
/**
51+
* @return array
52+
*/
53+
public function getConnectionInfo(): array
54+
{
55+
return $this->execute("terminus connection:info %s.dev --format=json", [
56+
$this->getSiteInfo()->getName()
57+
]);
58+
}
59+
60+
/**
61+
* @return string
62+
*/
63+
protected function getClonePath():string
64+
{
65+
return $this->getDefaultClonePathBase() . DIRECTORY_SEPARATOR . $this->getSiteInfo()->getName();
66+
}
67+
68+
/**
69+
* @return string
70+
*/
71+
protected function getGitCommand():string
72+
{
73+
return str_replace(
74+
$this->getSiteInfo()->getName(),
75+
$this->getClonePath(),
76+
$this->getConnectionInfo()['git_command']
77+
);
78+
}
79+
80+
/**
81+
* @return bool
82+
* @throws \Exception
83+
*/
84+
public function cloneFiles(OutputInterface $output): bool
85+
{
86+
87+
$this->execute($this->getGitCommand());
88+
if ($this->getLastStatus() !== 0) {
89+
throw new \Exception("Cannot clone site with terminus command." .
90+
join(PHP_EOL, $this->execResult));
91+
}
92+
$output->writeln(
93+
sprintf(
94+
"Site Code Folder: %s",
95+
$this->clonePath->getRealPath()
96+
)
97+
);
98+
}
99+
}

src/Models/Site.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,13 @@ public function updateServiceLevel($service_level)
478478
throw $e;
479479
}
480480
}
481+
482+
public function valid():bool
483+
{
484+
return (bool) $this->id;
485+
}
486+
487+
public function cloneLocalCopy()
488+
{
489+
}
481490
}

0 commit comments

Comments
 (0)