1 <?php
2
3 namespace Setup;
4
5 use Format;
6 use Service;
7 use Settings as SET;
8
9 10 11 12 13
14 class MySQL extends AbstractBinSetup {
15
16 17 18 19 20
21 protected $binchecker;
22
23 24 25 26 27
28 function __construct() {
29 $this->dest = DIR_TMP . 'mysql.zip';
30 $this->dest_unzip = DIR_TMP . 'mysql' . DIRECTORY_SEPARATOR;
31
32 $this->binchecker = new \BinChecker\MySQL();
33 $this->links = $this->binchecker->getLinks();
34
35 $this
36 ->promptDownload()
37 ->unzip()
38 ->copy()
39 ->editMyIni()
40 ->installService();
41 }
42
43 44 45 46 47 48
49 protected function installService() {
50 if(Service::exists('alomysql')) {
51 _echo('Removing previous AloWAMP MySQL service');
52 _echo(Service::delete('alomysql'));
53 }
54
55 _echo('Installing MySQL service');
56 _echo(Service::installExe('alomysql',
57 DIR_MYSQL .
58 $this->version .
59 DIRECTORY_SEPARATOR .
60 'bin' .
61 DIRECTORY_SEPARATOR .
62 'mysqld.exe alomysql',
63 'AloWAMP MySQL ' . $this->version));
64
65 return $this;
66 }
67
68 69 70 71 72 73
74 protected function editMyIni() {
75 $dest = DIR_MYSQL . $this->version . DIRECTORY_SEPARATOR . 'my.ini';
76 $dir = DIR_MYSQL . $this->version;
77
78 $contents = str_replace([
79 '{$basedir}',
80 '{$log-error}',
81 '{$datadir}',
82 '{$lc-messages-dir}'
83 ],
84 [
85 '"' . $dir . '"',
86 '"' . DIR_LOGS . 'mysql' . DIRECTORY_SEPARATOR . 'mysql.log"',
87 '"' . $dir . DIRECTORY_SEPARATOR . 'data"',
88 '"' . $dir . DIRECTORY_SEPARATOR . 'share"'
89 ],
90 file_get_contents(DIR_CORE . 'file_placeholders' . DIRECTORY_SEPARATOR . 'my.ini'));
91 if(file_put_contents($dest, $contents) !== false) {
92
93 }
94
95 return $this;
96 }
97
98 99 100 101 102 103
104 protected function unzip() {
105 _echo('It\'s a fairly large file so this next step might take a while..');
106
107 return parent::unzip();
108 }
109
110 111 112 113 114 115
116 protected function copy() {
117 $scan = scandir($this->dest_unzip);
118 Format::formatScandir($scan);
119 $dir = null;
120
121 foreach($scan as $s) {
122 if(is_dir($this->dest_unzip . $s)) {
123 $dir = $this->dest_unzip . $s;
124 break;
125 }
126 }
127
128 if(!$dir) {
129 die('Could not find the MySQL source directory in the unzipped files. Aborting.');
130 } else {
131 _echo('Copying downloaded contents. It\'s usually over 1GB so this might take a while...');
132 $source = $dir;
133 $this->unzipped_destination = DIR_MYSQL . $this->version;
134
135 if(!file_exists($this->unzipped_destination . DIRECTORY_SEPARATOR)) {
136 mkdir($this->unzipped_destination . DIRECTORY_SEPARATOR, 777, true);
137 }
138
139 shell_exec('xcopy /s /e "' . $source . '" "' . $this->unzipped_destination . '"');
140 $this->unzipped_destination .= DIRECTORY_SEPARATOR;
141
142 if(file_exists($this->unzipped_destination . 'bin')) {
143 _echo('Copy successful!');
144 $this->cleanup();
145 $this->updateSettings();
146 } else {
147 die('Failed to copy. Terminating setup.');
148 }
149
150 }
151
152 return $this;
153 }
154
155 156 157 158 159 160
161 protected function updateSettings() {
162 SET::$s->mysql_version = $this->version;
163 Set::$s->save();
164
165 return $this;
166 }
167 }