/
ScriptHandler.php
83 lines (72 loc) · 2.33 KB
/
ScriptHandler.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
<?php
/**
* @file
* Contains \DrupalProject\composer\ScriptHandler.
*/
namespace DrupalProject\composer;
use Composer\Script\Event;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
class ScriptHandler
{
protected static function getDrupalRoot($project_root)
{
return $project_root . '/web';
}
public static function createRequiredFiles(Event $event)
{
$fs = new Filesystem();
$root = static::getDrupalRoot(getcwd());
$dirs = [
'modules',
'profiles',
'themes',
];
// Required for unit testing
foreach ($dirs as $dir) {
if (!$fs->exists($root . '/'. $dir)) {
$fs->mkdir($root . '/'. $dir);
$fs->touch($root . '/'. $dir . '/.gitkeep');
}
}
// Create the files directory with chmod 0777
if (!$fs->exists($root . '/sites/default/files')) {
$oldmask = umask(0);
$fs->mkdir($root . '/sites/default/files', 0777);
umask($oldmask);
$event->getIO()->write("Create a sites/default/files directory with chmod 0777");
}
}
// This is called by the QuickSilver deploy hook to convert from
// a 'lean' repository to a 'fat' repository. This should only be
// called when using this repository as a custom upstream, and
// updating it with `terminus composer <site>.<env> update`. This
// is not used in the GitHub PR workflow.
public static function prepareForPantheon()
{
// Get rid of any .git directories that Composer may have added.
// n.b. Ideally, there are none of these, as removing them may
// impair Composer's ability to update them later. However, leaving
// them in place prevents us from pushing to Pantheon.
$dirsToDelete = [];
$finder = new Finder();
foreach (
$finder
->directories()
->in(getcwd())
->ignoreDotFiles(false)
->ignoreVCS(false)
->depth('> 0')
->name('.git')
as $dir) {
$dirsToDelete[] = $dir;
}
$fs = new Filesystem();
$fs->remove($dirsToDelete);
// Fix up .gitignore: remove everything above the "::: cut :::" line
$gitignoreFile = getcwd() . '/.gitignore';
$gitignoreContents = file_get_contents($gitignoreFile);
$gitignoreContents = preg_replace('/.*::: cut :::*/s', '', $gitignoreContents);
file_put_contents($gitignoreFile, $gitignoreContents);
}
}