Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 666
0.00% covered (danger)
0.00%
0 / 25
CRAP
0.00% covered (danger)
0.00%
0 / 1
DevDataUtils
0.00% covered (danger)
0.00%
0 / 666
0.00% covered (danger)
0.00%
0 / 25
7656
0.00% covered (danger)
0.00%
0 / 1
 fullResetDb
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 resetDbStructure
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 resetDbContent
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 dropDbTables
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
20
 truncateDbTables
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
20
 addDbStructure
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
42
 addDbContent
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
42
 getCurrentMigration
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 generateMigration
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
2
 migrateTo
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 writeDbBackup
0.00% covered (danger)
0.00%
0 / 42
0.00% covered (danger)
0.00%
0 / 1
132
 dumpDb
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 getDbStructureSql
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getDbStructureSqlFile
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 1
6
 getDbContentSql
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getDbContentSqlFile
0.00% covered (danger)
0.00%
0 / 67
0.00% covered (danger)
0.00%
0 / 1
110
 clearFiles
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
6
 addFiles
0.00% covered (danger)
0.00%
0 / 293
0.00% covered (danger)
0.00%
0 / 1
42
 tmpdir
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 mkdir
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 copy
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 mkimg
0.00% covered (danger)
0.00%
0 / 53
0.00% covered (danger)
0.00%
0 / 1
72
 mklog
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
20
 enqueueForTouch
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 touchEnqueued
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Olz\Common\Utils;
4
5use Ifsnop\Mysqldump\Mysqldump;
6use Symfony\Component\Console\Input\ArrayInput;
7use Symfony\Component\Console\Output\BufferedOutput;
8
9class DevDataUtils {
10    use WithUtilsTrait;
11
12    protected const FIXTURES_DIR = __DIR__.'/../../../fixtures/';
13    protected const TMP_DIR = __DIR__.'/../../../var/tmp/';
14
15    /** @var array<string> */
16    private array $enqueuedForTouch = [];
17
18    /** DO NOT CALL THIS FUNCTION ON PROD! */
19    public function fullResetDb(): void {
20        if ($this->envUtils()->getAppEnv() === 'prod') {
21            throw new \Exception("Are you fucking insane? You're on prod!");
22        }
23        // Overwrite database with dev content.
24        $this->dropDbTables();
25        $this->addDbStructure();
26        $this->addDbContent();
27        $this->migrateTo('latest');
28
29        // Initialize the non-code data file system at $data_path
30        $this->clearFiles();
31        $this->addFiles();
32    }
33
34    /** DO NOT CALL THIS FUNCTION ON PROD! */
35    public function resetDbStructure(): void {
36        if ($this->envUtils()->getAppEnv() === 'prod') {
37            throw new \Exception("Are you fucking insane? You're on prod!");
38        }
39        // Overwrite database with dev content.
40        $this->dropDbTables();
41        $this->addDbStructure();
42        $this->addDbContent();
43        $this->migrateTo('latest');
44
45        // Initialize the non-code data file system at $data_path
46        $this->addFiles();
47    }
48
49    /** DO NOT CALL THIS FUNCTION ON PROD! */
50    public function resetDbContent(): void {
51        if ($this->envUtils()->getAppEnv() === 'prod') {
52            throw new \Exception("Are you fucking insane? You're on prod!");
53        }
54        $this->truncateDbTables();
55        $this->addDbContent();
56    }
57
58    /** DO NOT CALL THIS FUNCTION ON PROD! */
59    public function dropDbTables(): void {
60        if ($this->envUtils()->getAppEnv() === 'prod') {
61            throw new \Exception("Are you fucking insane? You're on prod!");
62        }
63        $db = $this->dbUtils()->getDb();
64
65        // Remove all database tables.
66        $beg = microtime(true);
67        $result = $db->query("SHOW TABLES");
68        assert(!is_bool($result));
69        $table_names = [];
70        while ($row = $result->fetch_array()) {
71            $table_name = $row[0];
72            $table_names[] = $table_name;
73        }
74        $db->query('SET foreign_key_checks = 0');
75        foreach ($table_names as $table_name) {
76            $sql = "DROP TABLE `{$table_name}`";
77            $db->query($sql);
78        }
79        $db->query('SET foreign_key_checks = 1');
80        $duration = round(microtime(true) - $beg, 3);
81        $this->log()->debug("Dropping took {$duration}s");
82    }
83
84    /** DO NOT CALL THIS FUNCTION ON PROD! */
85    public function truncateDbTables(): void {
86        if ($this->envUtils()->getAppEnv() === 'prod') {
87            throw new \Exception("Are you fucking insane? You're on prod!");
88        }
89        $db = $this->dbUtils()->getDb();
90
91        // Remove all database tables.
92        $beg = microtime(true);
93        $result = $db->query("SHOW TABLES");
94        assert(!is_bool($result));
95        $table_names = [];
96        while ($row = $result->fetch_array()) {
97            $table_name = $row[0];
98            $table_names[] = $table_name;
99        }
100        $db->query('SET foreign_key_checks = 0');
101        foreach ($table_names as $table_name) {
102            $sql = "TRUNCATE TABLE `{$table_name}`";
103            $db->query($sql);
104        }
105        $db->query('SET foreign_key_checks = 1');
106        $duration = round(microtime(true) - $beg, 3);
107        $this->log()->debug("Truncating took {$duration}s");
108    }
109
110    /** DO NOT CALL THIS FUNCTION ON PROD! */
111    public function addDbStructure(): void {
112        if ($this->envUtils()->getAppEnv() === 'prod') {
113            throw new \Exception("Are you fucking insane? You're on prod!");
114        }
115        $db = $this->dbUtils()->getDb();
116        $dev_data_dir = self::FIXTURES_DIR.'db/';
117
118        // Overwrite database structure with dev content.
119        $beg = microtime(true);
120        $sql_content = file_get_contents("{$dev_data_dir}structure.sql") ?: '';
121        if ($db->multi_query($sql_content)) {
122            while ($db->next_result()) {
123                $result = $db->store_result();
124                if ($result) {
125                    $result->free();
126                }
127            }
128        }
129        $duration = round(microtime(true) - $beg, 3);
130        $this->log()->debug("Adding structure took {$duration}s");
131    }
132
133    /** DO NOT CALL THIS FUNCTION ON PROD! */
134    public function addDbContent(): void {
135        if ($this->envUtils()->getAppEnv() === 'prod') {
136            throw new \Exception("Are you fucking insane? You're on prod!");
137        }
138        $db = $this->dbUtils()->getDb();
139        $dev_data_dir = self::FIXTURES_DIR.'db/';
140
141        // Insert dev content into database.
142        $beg = microtime(true);
143        $db->query('SET foreign_key_checks = 0');
144        $sql_content = file_get_contents("{$dev_data_dir}content.sql") ?: '';
145        if ($db->multi_query($sql_content)) {
146            while ($db->next_result()) {
147                $result = $db->store_result();
148                if ($result) {
149                    $result->free();
150                }
151            }
152        }
153        $db->query('SET foreign_key_checks = 1');
154        $duration = round(microtime(true) - $beg, 3);
155        $this->log()->debug("Adding content took {$duration}s");
156    }
157
158    public function getCurrentMigration(): ?string {
159        $input = new ArrayInput(['--no-interaction' => true]);
160        $input->setInteractive(false);
161        $output = new BufferedOutput();
162        $this->symfonyUtils()->callCommand(
163            'doctrine:migrations:current',
164            $input,
165            $output
166        );
167        $is_match = preg_match('/^\s*([a-zA-Z0-9\\\]+)(\s|$)/', $output->fetch(), $matches);
168        return $is_match ? $matches[1] : null;
169    }
170
171    public function generateMigration(): string {
172        $input = new ArrayInput([
173            '--no-interaction' => true,
174        ]);
175        $input->setInteractive(false);
176        $output = new BufferedOutput();
177        $this->symfonyUtils()->callCommand(
178            'doctrine:migrations:diff',
179            $input,
180            $output
181        );
182        return $output->fetch();
183    }
184
185    public function migrateTo(string $version = 'latest'): string {
186        $input = new ArrayInput([
187            'version' => $version,
188            '--no-interaction' => true,
189        ]);
190        $input->setInteractive(false);
191        $output = new BufferedOutput();
192        $this->symfonyUtils()->callCommand(
193            'doctrine:migrations:migrate',
194            $input,
195            $output
196        );
197        return $output->fetch();
198    }
199
200    /**
201     * Writes an encrypted, self-contained database backup to the given file.
202     * The file can be decrypted with tools/decrypt_backup/decrypt_backup.php.
203     */
204    public function writeDbBackup(string $key, string $file_path): void {
205        if (!$key || strlen($key) < 10) {
206            throw new \Exception("No valid key");
207        }
208
209        $tmp_dir = $this->tmpdir();
210        $plain_path = "{$tmp_dir}backup.plain.sql";
211        $plain_fp = fopen($plain_path, 'w+');
212        assert((bool) $plain_fp);
213
214        $structure_path = $this->getDbStructureSqlFile();
215        $structure_fp = fopen($structure_path, 'r');
216        assert((bool) $structure_fp);
217        while ($chunk = fread($structure_fp, 1024)) {
218            fwrite($plain_fp, $chunk);
219        }
220        fclose($structure_fp);
221
222        fwrite($plain_fp, "\n\n----------\n\n\n");
223
224        $content_path = $this->getDbContentSqlFile();
225        $content_fp = fopen($content_path, 'r');
226        assert((bool) $content_fp);
227        while ($chunk = fread($content_fp, 1024)) {
228            fwrite($plain_fp, $chunk);
229        }
230        fclose($content_fp);
231
232        fclose($plain_fp);
233        unlink($structure_path);
234        unlink($content_path);
235
236        $cipher_path = "{$tmp_dir}backup.cipher.sql";
237        $cipher_fp = fopen($cipher_path, 'w+');
238        assert((bool) $cipher_fp);
239        $algo = 'aes-256-gcm';
240        $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algo) ?: 0);
241        fwrite($cipher_fp, openssl_encrypt(file_get_contents($plain_path) ?: '', $algo, $key, OPENSSL_RAW_DATA, $iv, $tag) ?: '');
242        fclose($cipher_fp);
243        unlink($plain_path);
244
245        $file_fp = fopen($file_path, 'w+');
246        assert((bool) $file_fp);
247        fwrite($file_fp, json_encode([
248            'algo' => $algo,
249            'iv' => base64_encode($iv),
250            'tag' => base64_encode($tag),
251        ]) ?: '{}');
252        fwrite($file_fp, "\n\n");
253        $cipher_fp = fopen($cipher_path, 'r');
254        assert((bool) $cipher_fp);
255        while (!feof($cipher_fp)) {
256            $chunk = fread($cipher_fp, 57 * 143);
257            $encoded = base64_encode($chunk ?: '');
258            $splitted = chunk_split($encoded, 76, "\r\n");
259            fwrite($file_fp, $splitted);
260        }
261        fclose($cipher_fp);
262        fclose($file_fp);
263        unlink($cipher_path);
264    }
265
266    public function dumpDb(): void {
267        $dev_data_dir = self::FIXTURES_DIR.'db/';
268
269        $sql_structure = $this->getDbStructureSql();
270        $sql_content = $this->getDbContentSql();
271        $sql_structure_path = "{$dev_data_dir}structure.sql";
272        $sql_content_path = "{$dev_data_dir}content.sql";
273        file_put_contents($sql_structure_path, $sql_structure);
274        file_put_contents($sql_content_path, $sql_content);
275    }
276
277    public function getDbStructureSql(): string {
278        $path = $this->getDbStructureSqlFile();
279        $content = file_get_contents($path) ?: '';
280        unlink($path);
281        return $content;
282    }
283
284    public function getDbStructureSqlFile(): string {
285        $tmp_dir = $this->tmpdir();
286        $env_utils = $this->envUtils();
287
288        $path_tmp = "{$tmp_dir}structure_tmp.sql";
289        $mysql_server = $env_utils->getMysqlServer();
290        $mysql_schema = $env_utils->getMysqlSchema();
291        $dump = new Mysqldump(
292            "mysql:host={$mysql_server};dbname={$mysql_schema}",
293            $env_utils->getMysqlUsername(),
294            $env_utils->getMysqlPassword(),
295            [
296                'skip-comments' => true,
297                'no-data' => true,
298                // This is the only way to exclude all views:
299                'include-views' => [''], // include only a view which does not exist.
300            ],
301        );
302        $dump->start($path_tmp);
303
304        $path = "{$tmp_dir}structure.sql";
305        $fp = fopen($path, 'w+');
306        assert((bool) $fp);
307
308        $current_migration = $this->getCurrentMigration();
309        fwrite(
310            $fp,
311            "-- Die Struktur der Datenbank der Webseite der OL Zimmerberg\n"
312            ."-- MIGRATION: {$current_migration}\n"
313            ."\n"
314        );
315        $fp_tmp = fopen($path_tmp, 'r');
316        assert((bool) $fp_tmp);
317        while ($chunk = fread($fp_tmp, 1024)) {
318            fwrite($fp, $chunk);
319        }
320        fclose($fp_tmp);
321        fclose($fp);
322        unlink($path_tmp);
323
324        return $path;
325    }
326
327    public function getDbContentSql(): string {
328        $path = $this->getDbContentSqlFile();
329        $content = file_get_contents($path) ?: '';
330        unlink($path);
331        return $content;
332    }
333
334    public function getDbContentSqlFile(): string {
335        $ignored_tables = [
336            'counter' => true,
337            'auth_requests' => true,
338            'messenger_messages' => true,
339            'sessions' => true,
340        ];
341        $batch_size = 100;
342
343        $tmp_dir = $this->tmpdir();
344        $db = $this->dbUtils()->getDb();
345        $current_migration = $this->getCurrentMigration();
346
347        $path = "{$tmp_dir}content.sql";
348        $fp = fopen($path, 'w+');
349        assert((bool) $fp);
350
351        fwrite(
352            $fp,
353            "-- Der Test-Inhalt der Datenbank der Webseite der OL Zimmerberg\n"
354            ."-- MIGRATION: {$current_migration}\n"
355            ."\n"
356            ."SET SQL_MODE = \"NO_AUTO_VALUE_ON_ZERO\";\n"
357            ."SET AUTOCOMMIT = 0;\n"
358            ."START TRANSACTION;\n"
359            ."SET time_zone = \"+00:00\";\n"
360        );
361
362        $res_tables = $db->query('SHOW TABLES');
363        assert(!is_bool($res_tables));
364        while ($row_tables = $res_tables->fetch_row()) {
365            $table_name = $row_tables[0];
366            fwrite($fp, "\n");
367            fwrite($fp, "-- Table {$table_name}\n");
368            if ($ignored_tables[$table_name] ?? false) {
369                fwrite($fp, "-- ({$table_name} omitted)\n");
370                continue;
371            }
372            $offset = 0;
373            while (true) {
374                $res_contents = $db->query("SELECT * FROM `{$table_name}` LIMIT {$offset},{$batch_size}");
375                assert(!is_bool($res_contents));
376                if ($res_contents->num_rows === 0) {
377                    unset($res_contents);
378                    gc_collect_cycles();
379                    break;
380                }
381                fwrite($fp, "INSERT INTO {$table_name}\n");
382                $content_fields = $res_contents->fetch_fields();
383                $field_names = [];
384                foreach ($content_fields as $field) {
385                    $field_names[] = $field->name;
386                }
387                $field_names_sql = implode('`, `', $field_names);
388                fwrite($fp, "    (`{$field_names_sql}`)\n");
389                fwrite($fp, "VALUES\n");
390                $first = true;
391                while ($row_contents = $res_contents->fetch_assoc()) {
392                    if ($first) {
393                        $first = false;
394                    } else {
395                        fwrite($fp, ",\n");
396                    }
397                    $field_values = [];
398                    foreach ($field_names as $name) {
399                        $content = $row_contents[$name] ?? null;
400                        if ($content === null) {
401                            $field_values[] = 'NULL';
402                        } else {
403                            $sane_content = $db->escape_string("{$content}");
404                            $field_values[] = "'{$sane_content}'";
405                        }
406                    }
407                    $field_values_sql = implode(', ', $field_values);
408                    fwrite($fp, "    ({$field_values_sql})");
409                }
410                fwrite($fp, ";\n");
411                $offset += $batch_size;
412                unset($res_contents);
413                gc_collect_cycles();
414            }
415        }
416        fwrite($fp, "\n");
417        fwrite($fp, "COMMIT;\n");
418        fclose($fp);
419        return $path;
420    }
421
422    /** DO NOT CALL THIS FUNCTION ON PROD! */
423    public function clearFiles(): void {
424        if ($this->envUtils()->getAppEnv() === 'prod') {
425            throw new \Exception("Are you fucking insane? You're on prod!");
426        }
427        $data_path = $this->envUtils()->getDataPath();
428        $general_utils = $this->generalUtils();
429
430        // Remove existing data.
431        $general_utils->removeRecursive("{$data_path}downloads");
432        $general_utils->removeRecursive("{$data_path}files");
433        $general_utils->removeRecursive("{$data_path}img");
434        $general_utils->removeRecursive("{$data_path}movies");
435        $general_utils->removeRecursive("{$data_path}olz_mitglieder");
436        $general_utils->removeRecursive("{$data_path}OLZimmerbergAblage");
437        $general_utils->removeRecursive("{$data_path}panini_data");
438        $general_utils->removeRecursive("{$data_path}pdf");
439        $general_utils->removeRecursive("{$data_path}results");
440        $general_utils->removeRecursive("{$data_path}temp");
441    }
442
443    /** DO NOT CALL THIS FUNCTION ON PROD! */
444    public function addFiles(): void {
445        if ($this->envUtils()->getAppEnv() === 'prod') {
446            throw new \Exception("Are you fucking insane? You're on prod!");
447        }
448        $private_path = $this->envUtils()->getPrivatePath();
449        $data_path = $this->envUtils()->getDataPath();
450
451        $sample_path = self::FIXTURES_DIR.'sample-data/';
452
453        $this->enqueuedForTouch = [];
454
455        // Build downloads/
456        $this->mkdir("{$data_path}downloads");
457
458        // Build files/
459        $this->mkdir("{$data_path}files");
460        $this->mkdir("{$data_path}files/downloads");
461        $this->mkdir("{$data_path}files/downloads/1");
462        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/downloads/1/MIGRATED0000000000010001.pdf");
463        $this->mkdir("{$data_path}files/downloads/3");
464        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/downloads/3/XV4x94BJaf2JCPWvB8DDqTyt.pdf");
465
466        $this->mkdir("{$data_path}files/news");
467        $this->mkdir("{$data_path}files/news/3");
468        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/news/3/MIGRATED0000000000030001.pdf");
469        $this->mkdir("{$data_path}files/news/4");
470        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/news/4/xMpu3ExjfBKa8Cp35bcmsDgq.pdf");
471        $this->mkdir("{$data_path}files/news/10");
472        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/news/10/gAQa_kYXqXTP1_DKKU1s1pGr.csv");
473        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/news/10/8kCalo9sQtu2mrgrmMjoGLUW.pdf");
474        $this->mkdir("{$data_path}files/news/6403");
475        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/news/6403/MIGRATED0000000064030001.pdf");
476
477        $this->mkdir("{$data_path}files/questions");
478        $this->mkdir("{$data_path}files/questions/1");
479        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/questions/1/4a7J72vVQFrqkboyD358S4cf.pdf");
480
481        $this->mkdir("{$data_path}files/roles");
482        $this->mkdir("{$data_path}files/roles/5");
483        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/roles/5/c44s3s8QjwZd2WYTEVg3iW9k.pdf");
484
485        $this->mkdir("{$data_path}files/snippets");
486        $this->mkdir("{$data_path}files/snippets/24");
487        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/snippets/24/AXfZYP3eyLKTWJmfBRGTua7H.pdf");
488
489        $this->mkdir("{$data_path}files/termine");
490        $this->mkdir("{$data_path}files/termine/2");
491        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/termine/2/MIGRATED0000000000020001.pdf");
492        $this->mkdir("{$data_path}files/termine/5");
493        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/termine/5/MIGRATED0000000000050001.pdf");
494        $this->mkdir("{$data_path}files/termine/7");
495        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/termine/7/Kzt5p5g6cjM5k9CXdVaSsGFx.pdf");
496        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/termine/7/p4d8NzGMiQXuGEfnAHVbbkwc.pdf");
497
498        $this->mkdir("{$data_path}files/termin_labels");
499        $this->mkdir("{$data_path}files/termin_labels/3");
500        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/termin_labels/3/6f6novQPv2fjHGzzguXE6nzi.pdf");
501        $this->mkdir("{$data_path}files/termin_labels/4");
502        $this->copy("{$sample_path}sample-icon_20.svg", "{$data_path}files/termin_labels/4/EM8hA6vye74doeon2RWzZyRf.svg");
503
504        $this->mkdir("{$data_path}files/termin_templates");
505        $this->mkdir("{$data_path}files/termin_templates/2");
506        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}files/termin_templates/2/qjhUey6Lc6svXsmUcSaguWkJ.pdf");
507
508        // Build img/
509        $this->mkdir("{$data_path}img");
510        $this->mkdir("{$data_path}img/weekly_picture");
511        $this->mkdir("{$data_path}img/weekly_picture/1");
512        $this->mkdir("{$data_path}img/weekly_picture/1/img");
513        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/weekly_picture/1/img/ed48ksmyjVgRsaKXUXmmcbRN.jpg", 800, 600);
514        $this->mkdir("{$data_path}img/weekly_picture/2");
515        $this->mkdir("{$data_path}img/weekly_picture/2/img");
516        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/weekly_picture/2/img/C8k84ncvWyVptk6kjtMJxTUu.jpg", 800, 600);
517        $this->mkdir("{$data_path}img/fuer_einsteiger");
518        $this->mkdir("{$data_path}img/fuer_einsteiger/img");
519        $this->mkdir("{$data_path}img/fuer_einsteiger/thumb");
520        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/orientierungslauf_001.jpg", 800, 600);
521        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/orientierungslauf_002.jpg", 800, 600);
522        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/orientierungslauf_003.jpg", 800, 600);
523        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/orientierungslauf_004.jpg", 800, 600);
524        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/was_ist_ol_001.jpg", 800, 600);
525        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_001.jpg", 800, 600);
526        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_002.jpg", 800, 600);
527        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_003.jpg", 800, 600);
528        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_004.jpg", 800, 600);
529        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_005.jpg", 800, 600);
530        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_006.jpg", 800, 600);
531        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_007.jpg", 800, 600);
532        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_008.jpg", 800, 600);
533        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_009.jpg", 800, 600);
534        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_010.jpg", 800, 600);
535        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_011.jpg", 800, 600);
536        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_012.jpg", 800, 600);
537        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_013.jpg", 800, 600);
538        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_014.jpg", 800, 600);
539        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_015.jpg", 800, 600);
540        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ol_zimmerberg_016.jpg", 800, 600);
541        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/wie_anfangen_001.jpg", 800, 600);
542        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/wie_anfangen_002.jpg", 800, 600);
543        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/wie_anfangen_003.jpg", 800, 600);
544        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/wie_anfangen_004.jpg", 800, 600);
545        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_001.jpg", 800, 600);
546        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_002.jpg", 800, 600);
547        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_003.jpg", 800, 600);
548        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_004.jpg", 800, 600);
549        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_005.jpg", 800, 600);
550        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_006.jpg", 800, 600);
551        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_007.jpg", 800, 600);
552        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_008.jpg", 800, 600);
553        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_009.jpg", 800, 600);
554        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_010.jpg", 800, 600);
555        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_011.jpg", 800, 600);
556        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_012.jpg", 800, 600);
557        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_013.jpg", 800, 600);
558        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_014.jpg", 800, 600);
559        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_015.jpg", 800, 600);
560        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/trainings_016.jpg", 800, 600);
561        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/pack_die_chance_001.jpg", 800, 600);
562        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ansprechperson_001.jpg", 800, 600);
563        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ansprechperson_002.jpg", 800, 600);
564        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ansprechperson_003.jpg", 800, 600);
565        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/fuer_einsteiger/img/ansprechperson_004.jpg", 800, 600);
566
567        // Generate thumbs
568        if (function_exists('shell_exec')) {
569            $thumbize_src = __DIR__."/../../../tools/fuer_einsteiger/thumbize.sh";
570            $thumbize_dest = "{$data_path}img/fuer_einsteiger/thumbize.sh";
571            if (is_file($thumbize_dest)) {
572                unlink($thumbize_dest);
573            }
574            $this->copy($thumbize_src, $thumbize_dest);
575            $pwd = getcwd();
576            chdir("{$data_path}img/fuer_einsteiger");
577            shell_exec("sh ./thumbize.sh");
578            if ($pwd) {
579                chdir($pwd);
580            }
581        }
582
583        $this->mkdir("{$data_path}img/karten");
584        $this->mkdir("{$data_path}img/karten/1");
585        $this->mkdir("{$data_path}img/karten/1/img");
586        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/karten/1/img/MIGRATED0000000000010001.jpg", 800, 600);
587        $this->mkdir("{$data_path}img/karten/3");
588        $this->mkdir("{$data_path}img/karten/3/img");
589        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/karten/3/img/6R3bpgwcCU3SfUF8vCpepzRJ.jpg", 800, 600);
590
591        $this->mkdir("{$data_path}img/news");
592        $this->mkdir("{$data_path}img/news/3");
593        $this->mkdir("{$data_path}img/news/3/img");
594        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/3/img/MIGRATED0000000000030001.jpg", 800, 600);
595        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/3/img/MIGRATED0000000000030002.jpg", 800, 600);
596        $this->mkdir("{$data_path}img/news/4");
597        $this->mkdir("{$data_path}img/news/4/img");
598        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/4/img/xkbGJQgO5LFXpTSz2dCnvJzu.jpg", 800, 600);
599        $this->mkdir("{$data_path}img/news/6");
600        $this->mkdir("{$data_path}img/news/6/img");
601        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/6/img/eGbiJQgOyLF5p6S92kC3vTzE.jpg", 600, 800);
602        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/6/img/Frw83uTOyLF5p6S92kC7zpEW.jpg", 800, 600);
603        $this->mkdir("{$data_path}img/news/7");
604        $this->mkdir("{$data_path}img/news/7/img");
605        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/7/img/aRJIflbxtkF5p6S92k470912.jpg", 800, 600);
606        $this->mkdir("{$data_path}img/news/8");
607        $this->mkdir("{$data_path}img/news/8/img");
608        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/8/img/9GjbtlsSu96AWZ-oH0rHjxup.jpg", 800, 600);
609        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/8/img/zUXE3aKfbK3edmqS35FhaF8g.jpg", 800, 600);
610        $this->mkdir("{$data_path}img/news/10");
611        $this->mkdir("{$data_path}img/news/10/img");
612        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/10/img/DvDB8QkHcGuxQ4lAFwyvHnVd.jpg", 800, 600);
613        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/10/img/OOVJIqrWlitR_iTZuIIhztKC.jpg", 800, 600);
614        $this->mkdir("{$data_path}img/news/1201");
615        $this->mkdir("{$data_path}img/news/1201/img");
616        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1201/img/MIGRATED0000000012010001.jpg", 800, 600);
617        $this->mkdir("{$data_path}img/news/1202");
618        $this->mkdir("{$data_path}img/news/1202/img");
619        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1202/img/MIGRATED0000000012020001.jpg", 800, 600);
620        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1202/img/MIGRATED0000000012020002.jpg", 800, 600);
621        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1202/img/MIGRATED0000000012020003.jpg", 600, 800);
622        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1202/img/MIGRATED0000000012020004.jpg", 800, 600);
623        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1202/img/MIGRATED0000000012020005.jpg", 800, 300);
624        $this->mkdir("{$data_path}img/news/1203");
625        $this->mkdir("{$data_path}img/news/1203/img");
626        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1203/img/MIGRATED0000000012030001.jpg", 800, 600);
627        $this->mkdir("{$data_path}img/news/1203/thumb");
628        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1203/thumb/MIGRATED0000000012030001.jpg\$128.jpg", 128, 96);
629        $this->mkdir("{$data_path}img/news/1206");
630        $this->mkdir("{$data_path}img/news/1206/img");
631        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1206/img/MIGRATED0000000012060001.jpg", 800, 600);
632        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1206/img/MIGRATED0000000012060002.jpg", 800, 600);
633        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1206/img/MIGRATED0000000012060003.jpg", 800, 600);
634        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1206/img/MIGRATED0000000012060004.jpg", 800, 600);
635        $this->mkdir("{$data_path}img/news/1206/thumb");
636        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1206/thumb/MIGRATED0000000012060001.jpg\$128.jpg", 128, 96);
637        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1206/thumb/MIGRATED0000000012060002.jpg\$128.jpg", 128, 96);
638        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1206/thumb/MIGRATED0000000012060003.jpg\$128.jpg", 128, 96);
639        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/1206/thumb/MIGRATED0000000012060004.jpg\$128.jpg", 128, 96);
640        $this->mkdir("{$data_path}img/news/6401");
641        $this->mkdir("{$data_path}img/news/6401/img");
642        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/6401/img/MIGRATED0000000064010001.jpg", 800, 600);
643        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/6401/img/MIGRATED0000000064010002.jpg", 800, 600);
644        $this->mkdir("{$data_path}img/news/6403");
645        $this->mkdir("{$data_path}img/news/6403/img");
646        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/news/6403/img/MIGRATED0000000064030001.jpg", 800, 600);
647
648        $this->mkdir("{$data_path}img/questions");
649        $this->mkdir("{$data_path}img/questions/1");
650        $this->mkdir("{$data_path}img/questions/1/img");
651        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/questions/1/img/bKfDuE4hocQhbw9FGMD7WCW3.jpg", 800, 600);
652
653        $this->mkdir("{$data_path}img/roles");
654        $this->mkdir("{$data_path}img/roles/5");
655        $this->mkdir("{$data_path}img/roles/5/img");
656        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/roles/5/img/ZntVatFCHj3h8KZh7LyiB9x5.jpg", 800, 600);
657
658        $this->mkdir("{$data_path}img/snippets");
659        $this->mkdir("{$data_path}img/snippets/14");
660        $this->mkdir("{$data_path}img/snippets/14/img");
661        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/snippets/14/img/myjGV7ADStN8rITm5OSy9c48.jpg", 800, 800);
662        $this->mkdir("{$data_path}img/snippets/24");
663        $this->mkdir("{$data_path}img/snippets/24/img");
664        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/snippets/24/img/oCGvpb96V6bZNLoQNe8djJgw.jpg", 800, 600);
665
666        $this->mkdir("{$data_path}img/termine");
667        $this->mkdir("{$data_path}img/termine/5");
668        $this->mkdir("{$data_path}img/termine/5/img");
669        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/termine/5/img/Ffpi3PK5wBjKfN4etpvGK3ti.jpg", 800, 600);
670        $this->mkdir("{$data_path}img/termine/10");
671        $this->mkdir("{$data_path}img/termine/10/img");
672        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/termine/10/img/659gCbqzigX8D37XgWMbedB3.jpg", 800, 600);
673        $this->mkdir("{$data_path}img/termine/13");
674        $this->mkdir("{$data_path}img/termine/13/img");
675        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/termine/13/img/8EKYh2n8DZWShYMWo9ZRnor5.jpg", 800, 600);
676
677        $this->mkdir("{$data_path}img/termin_labels");
678        $this->mkdir("{$data_path}img/termin_labels/3");
679        $this->mkdir("{$data_path}img/termin_labels/3/img");
680        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/termin_labels/3/img/QQ8ZApZjsNSBM2wKrkRQxXZG.jpg", 800, 600);
681
682        $this->mkdir("{$data_path}img/termin_locations");
683        $this->mkdir("{$data_path}img/termin_locations/1");
684        $this->mkdir("{$data_path}img/termin_locations/1/img");
685        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/termin_locations/1/img/2ZiW6T9biPNjEERzj5xjLRDz.jpg", 800, 600);
686
687        $this->mkdir("{$data_path}img/termin_templates");
688        $this->mkdir("{$data_path}img/termin_templates/2");
689        $this->mkdir("{$data_path}img/termin_templates/2/img");
690        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/termin_templates/2/img/bv3KeYVKDJNg3MTyjhSQsDRx.jpg", 800, 600);
691
692        $this->mkdir("{$data_path}img/users");
693        $this->mkdir("{$data_path}img/users/1");
694        $this->mkdir("{$data_path}img/users/1/img");
695        $this->mkdir("{$data_path}img/users/1/thumb");
696        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/users/1/img/8sVwnV3aAEtQUUxmQYFmojMs.jpg", 300, 300);
697        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/users/1/thumb/8sVwnV3aAEtQUUxmQYFmojMs.jpg\$256.jpg", 256, 256);
698        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/users/1/thumb/8sVwnV3aAEtQUUxmQYFmojMs.jpg\$128.jpg", 128, 128);
699        $this->mkdir("{$data_path}img/users/3");
700        $this->mkdir("{$data_path}img/users/3/img");
701        $this->mkdir("{$data_path}img/users/3/thumb");
702        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/users/3/img/oyLeyPTaCfmadcm5ShEJ236e.jpg", 150, 150);
703        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "img/users/3/thumb/oyLeyPTaCfmadcm5ShEJ236e.jpg\$128.jpg", 128, 128);
704
705        // Build movies/
706        $this->mkdir("{$data_path}movies");
707
708        // Build olz_mitglieder/
709        $this->mkdir("{$data_path}olz_mitglieder");
710        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "olz_mitglieder/max_muster.jpg", 84, 120);
711
712        // Build OLZimmerbergAblage/
713        $this->mkdir("{$data_path}OLZimmerbergAblage");
714        $dokumente_path = "{$data_path}OLZimmerbergAblage/OLZ Dokumente";
715        $this->mkdir("{$dokumente_path}");
716        $this->mkdir("{$dokumente_path}/vorstand");
717        $this->copy("{$sample_path}sample-document.pdf", "{$dokumente_path}/vorstand/mitgliederliste.pdf");
718        $this->mkdir("{$dokumente_path}/vorstand/protokolle");
719        $this->copy("{$sample_path}sample-document.pdf", "{$dokumente_path}/vorstand/protokolle/protokoll.pdf");
720        $this->mkdir("{$dokumente_path}/karten");
721        $this->copy("{$sample_path}sample-document.pdf", "{$dokumente_path}/karten/uebersicht.pdf");
722        $this->mkdir("{$dokumente_path}/karten/wald");
723        $this->copy("{$sample_path}sample-document.pdf", "{$dokumente_path}/karten/wald/buchstabenwald.pdf");
724
725        // Build panini_data/
726        $this->mkdir("{$data_path}panini_data");
727        $this->mkdir("{$data_path}panini_data/cache");
728        $this->mkdir("{$data_path}panini_data/fonts");
729        $this->mkdir("{$data_path}panini_data/fonts/OpenSans");
730        $this->copy("{$sample_path}sample-font.ttf", "{$data_path}panini_data/fonts/OpenSans/OpenSans-SemiBold.ttf");
731        $this->copy("{$sample_path}sample-font.php", "{$data_path}panini_data/fonts/OpenSans/OpenSans-SemiBold.php");
732        $this->copy("{$sample_path}sample-font.z", "{$data_path}panini_data/fonts/OpenSans/OpenSans-SemiBold.z");
733        $this->mkdir("{$data_path}panini_data/masks");
734        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/topP_1517x2091.png", 1517, 2091);
735        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/bottomP_1517x2091.png", 1517, 2091);
736        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/associationP_1517x2091.png", 1517, 2091);
737        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/masks/associationStencilP_1517x2091.png", 1517, 2091);
738        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/topP_1594x2303.png", 1594, 2303);
739        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/topL_2303x1594.png", 2303, 1594);
740        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/bottomP_1594x2303.png", 1594, 2303);
741        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/bottomL_2303x1594.png", 2303, 1594);
742        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/associationP_1594x2303.png", 1594, 2303);
743        $this->mkimg("{$sample_path}sample-mask.png", $data_path, "panini_data/masks/associationL_2303x1594.png", 2303, 1594);
744        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/masks/associationStencilP_1594x2303.png", 1594, 2303);
745        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/masks/associationStencilL_2303x1594.png", 2303, 1594);
746        $this->mkdir("{$data_path}panini_data/wappen");
747        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/wappen/thalwil.jpg", 100, 100);
748        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/wappen/other.jpg", 100, 100);
749        $this->mkdir("{$data_path}panini_data/portraits");
750        $this->mkdir("{$data_path}panini_data/portraits/1001");
751        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/portraits/1001/vptD8fzvXIhv_6X32Zkw2s5s.jpg", 800, 600);
752        $this->mkdir("{$data_path}panini_data/portraits/1002");
753        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/portraits/1002/LkGdXukqgYEdnWpuFHfrJkr7.jpg", 800, 600);
754        $this->mkdir("{$data_path}panini_data/other");
755        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/other/portrait.jpg", 600, 800);
756        $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/other/landscape.jpg", 800, 600);
757        for ($i = 1003; $i <= 1012; $i++) {
758            $this->mkdir("{$data_path}panini_data/portraits/{$i}");
759            $this->mkimg("{$sample_path}sample-picture.jpg", $data_path, "panini_data/portraits/{$i}/LkGdXukqgYEdnWpuFHfrJkr7.jpg", 800, 600);
760        }
761
762        // Build pdf/
763        $this->mkdir("{$data_path}pdf");
764        $this->copy("{$sample_path}sample-document.pdf", "{$data_path}pdf/trainingsprogramm.pdf");
765
766        // Build results/
767        $this->mkdir("{$data_path}results");
768        $this->copy("{$sample_path}sample-results.xml", "{$data_path}results/results.xml");
769        $this->copy("{$sample_path}sample-results.xml", "{$data_path}results/2020-termine-7.xml");
770
771        // Build temp/
772        $this->mkdir("{$data_path}temp");
773
774        // Build logs/
775        $this->mkdir("{$private_path}logs");
776        $this->mklog("{$private_path}logs/merged-2020-08-13.log", "2020-08-13");
777        $this->mklog("{$private_path}logs/merged-2020-08-14.log", "2020-08-14");
778        $this->mklog("{$private_path}logs/merged-2020-08-15.log", "2020-08-15");
779        $this->mkdir("{$private_path}logs/server");
780        $this->mklog("{$private_path}logs/server/access_ssl_log", "2020-08-15");
781        $this->mklog("{$private_path}logs/server/access_ssl_log.processed", "2020-08-14");
782        $this->mklog("{$private_path}logs/server/access_ssl_log.processed.1", "2020-08-13");
783        $this->mklog("{$private_path}logs/server/access_ssl_log.processed.2", "2020-08-12");
784
785        // Build sessions
786        $this->mkdir("{$private_path}sessions");
787
788        $this->touchEnqueued(1584118800);
789    }
790
791    protected function tmpdir(): string {
792        $tmp_dir = self::TMP_DIR;
793        if (!is_dir($tmp_dir)) {
794            mkdir($tmp_dir, 0o777, true);
795        }
796        return $tmp_dir;
797    }
798
799    protected function mkdir(string $path, int $mode = 0o777, bool $recursive = false): void {
800        if (!is_dir($path)) {
801            mkdir($path, $mode, $recursive);
802        }
803        $this->enqueueForTouch($path);
804    }
805
806    protected function copy(string $source, string $dest): void {
807        if (!is_file($dest)) {
808            copy($source, $dest);
809        }
810        $this->enqueueForTouch($dest);
811    }
812
813    /**
814     * @param int<1, max> $width
815     * @param int<1, max> $height
816     */
817    protected function mkimg(
818        string $source_path,
819        string $data_path,
820        string $destination_relative_path,
821        int $width,
822        int $height,
823    ): void {
824        $destination_path = "{$data_path}{$destination_relative_path}";
825        if (is_file($destination_path)) {
826            return;
827        }
828        $tmp_dir = $this->tmpdir();
829        $flat_destination_relative_path = str_replace('/', '___', $destination_relative_path);
830        $extension_pos = strrpos($flat_destination_relative_path, '.') ?: 0;
831        $ident = substr($flat_destination_relative_path, 0, $extension_pos);
832        $extension = substr($flat_destination_relative_path, $extension_pos);
833        $tmp_basename = "{$ident}___{$width}x{$height}{$extension}";
834        $tmp_path = "{$tmp_dir}{$tmp_basename}";
835        if (!is_file($tmp_path)) {
836            $info = getimagesize($source_path);
837            $source_width = $info[0] ?? 0;
838            $source_height = $info[1] ?? 0;
839            $image_type = $info[2] ?? 0;
840            $source = null;
841            if ($image_type === 2) {
842                $source = imagecreatefromjpeg($source_path);
843            } elseif ($image_type === 3) {
844                $source = imagecreatefrompng($source_path);
845            }
846            if (!$source) {
847                throw new \Exception("mkimg: Image must be JPEG or PNG, was: {$image_type}");
848            }
849            $destination = imagecreatetruecolor($width, $height);
850            imagealphablending($destination, false);
851            imagesavealpha($destination, true);
852            imagecopyresampled(
853                $destination,
854                $source,
855                0,
856                0,
857                0,
858                0,
859                $width,
860                $height,
861                $source_width,
862                $source_height,
863            );
864            $red = imagecolorallocate($destination, 255, 0, 0);
865            assert($red !== false);
866            $hash = intval(substr(md5($destination_relative_path), 0, 1), 16);
867            $x = floor($hash / 4) * $width / 4;
868            $y = floor($hash % 4) * $height / 4;
869            imagefilledrectangle(
870                $destination,
871                intval(round($x)),
872                intval(round($y)),
873                intval(round($x + $width / 4)),
874                intval(round($y + $height / 4)),
875                $red
876            );
877            if (preg_match('/\.jpg$/', $destination_relative_path)) {
878                imagejpeg($destination, $tmp_path, 90);
879            } else {
880                imagepng($destination, $tmp_path);
881            }
882        }
883        $this->copy($tmp_path, $destination_path);
884    }
885
886    protected function mklog(string $file_path, string $iso_date): void {
887        $log_levels = [
888            'DEBUG',
889            'INFO',
890            'NOTICE',
891            'WARNING',
892            'ERROR',
893            'CRITICAL',
894            'ALERT',
895            'EMERGENCY',
896        ];
897        $num_log_levels = count($log_levels);
898        $fp = fopen($file_path, 'w+');
899        assert($fp !== false);
900        $long_line = 'Wow,';
901        for ($i = 0; $i < 1000; $i++) {
902            $long_line .= ' so much content';
903        }
904        for ($i = 0; $i < 1440; $i++) {
905            $time = str_pad(strval(floor($i / 60)), 2, '0', STR_PAD_LEFT).':'.
906                str_pad(strval(floor($i % 60)), 2, '0', STR_PAD_LEFT).':'.
907                str_pad(strval(random_int(0, 59)), 2, '0', STR_PAD_LEFT).'.'.
908                str_pad(strval(random_int(0, 999999)), 6, '0', STR_PAD_LEFT);
909            $level = $log_levels[$i % $num_log_levels];
910            $fill_up = ($i % ($num_log_levels + 1)) === 0 ? $long_line : '';
911            $line = "[{$iso_date}T{$time}+01:00] Command:ProcessEmail.{$level}: Something happened... {$fill_up} [] []\n";
912            fwrite($fp, $line);
913        }
914        fclose($fp);
915    }
916
917    protected function enqueueForTouch(string $path): void {
918        $this->enqueuedForTouch[] = $path;
919    }
920
921    protected function touchEnqueued(?int $timestamp): void {
922        foreach ($this->enqueuedForTouch as $path) {
923            touch($path, $timestamp, $timestamp);
924        }
925    }
926}