forked from drupal-composer/drupal-project
/
RoboFile.php
136 lines (112 loc) · 3.33 KB
/
RoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks {
protected function getProjectRoot() {
return realpath(__DIR__ . '/../../');
}
protected function getVendorDir() {
return $this->getProjectRoot() . '/vendor';
}
protected function getVendorBin() {
return $this->getProjectRoot() . '/vendor/bin';
}
protected function getWebRoot() {
return $this->getProjectRoot() . '/web';
}
protected function getTmpDir() {
return $this->getProjectRoot() . '/tmp';
}
protected function getDrush() {
return $this->getVendorBin() . '/drush';
}
protected function getVersionFile() {
return $this->getVendorDir() . '/.drupal-version';
}
public function versionDump() {
$this->taskWriteToFile($this->getVersionFile())
->text(\Drupal::VERSION)
->run();
}
public function versionRemove() {
$this->taskFilesystemStack()
->remove($this->getVersionFile())
->run();
}
public function updateIfNewerVersion() {
$versionFile = $this->getVersionFile();
if (file_exists($versionFile)) {
$previousVersion = file_get_contents($versionFile);
$this->versionRemove();
$currentVersion = str_replace('0-dev', 'x', \Drupal::VERSION);
if ($currentVersion != $previousVersion) {
$this->say("Drupal core updated from version $previousVersion to $currentVersion; updateing scaffolding files.");
$this->update("drupal-$currentVersion");
}
else {
$this->say("Drupal core version did not change; skipping scaffolding update.");
}
}
}
public function update($version = NULL) {
if (!isset($version)) {
$version = 'drupal-8';
}
$this->stopOnFail();
$tmpDir = $this->getTmpDir();
$confDir = $this->getWebRoot() . '/sites/default';
$confDirOriginalPerms = fileperms($confDir);
$this->taskFilesystemStack()
->mkdir($tmpDir)
->chmod($confDir, 0755)
->run();
$this->taskCleanDir([$tmpDir])
->run();
$this->taskExec($this->getDrush())
->args(['dl', $version])
->args("--root=$tmpDir")
->args("--destination=$tmpDir")
->args('--drupal-project-rename=drupal-8')
->args('--quiet')
->args('--yes')
->run();
$this->taskRsync()
->fromPath("$tmpDir/drupal-8")
->toPath($this->getWebRoot())
->exclude('.gitkeep')
->exclude('autoload.php')
->exclude('composer.json')
->exclude('composer.lock')
->exclude('core')
->exclude('drush')
->exclude('example.gitignore')
->exclude('LICENSE.txt')
->exclude('README.txt')
->exclude('vendor')
->exclude('sites')
->exclude('themes')
->exclude('profiles')
->exclude('modules')
->run();
$default_settings = [
'sites/default/default.settings.php',
'sites/default/default.services.yml',
'sites/example.settings.local.php',
'sites/example.sites.php'
];
foreach ($default_settings as $file) {
$this->taskRsync()
->fromPath("$tmpDir/drupal-8/" . $file)
->toPath($this->getWebRoot() . '/' . $file)
->run();
}
$this->taskDeleteDir($tmpDir)
->run();
$this->taskFilesystemStack()
->chmod($confDir, $confDirOriginalPerms)
->run();
}
}