-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollback.php
53 lines (42 loc) · 1.54 KB
/
rollback.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
<?php
require_once 'db/Connection.php';
require_once 'vendor/autoload.php';
$db = new Connection;
$db->toDatabase("DROP TABLE `state`,`status`,`profile`, `others`, `projects`, `skills`, `contacts`, template_user, `template`, `users`");
//remove arquivos
function removeAllFilesAndSubdirectories($directory) {
if (is_dir($directory)) {
$files = scandir($directory);
foreach ($files as $file) {
if ($file !== '.' && $file !== '..') {
$path = $directory . '/' . $file;
if (is_dir($path)) {
removeAllFilesAndSubdirectories($path);
rmdir($path);
} else {
unlink($path);
}
}
}
}
}
$directory = 'images/users/';
removeAllFilesAndSubdirectories($directory);
echo "Image files deleted\n";
echo "Rollback executed!";
echo "\nDatabase deleted successfully!\n\n";
$migrations = scandir(__DIR__ . '/db/migrations');
foreach ($migrations as $migration) {
if ($migration === '.' || $migration === '..') {
continue;
}
require_once 'db/migrations/' . $migration;
echo "\nMigration done: $migration\n";
}
$dbB = new Connection;
$dbB->toDatabase("INSERT INTO users VALUES(NULL, 'admin', MD5(".$_ENV['DB_PASSWORD']."))");
$db->toDatabase("INSERT INTO template VALUES(NULL, 'default', 1)");
$db->toDatabase("INSERT INTO template_user VALUES(NULL, 1, 1)");
echo "\nUser state created successfully!!\n";;
echo "\nUser admin created successfully!!\n";;
?>