-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.php
56 lines (44 loc) · 1.87 KB
/
run.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
#!/usr/bin/env php
<?php
namespace Datto\DatabaseAnalyzer\Database;
use Datto\DatabaseAnalyzer\Utility\Configuration;
use Datto\DatabaseAnalyzer\Utility\Filesystem;
use Datto\DatabaseAnalyzer\Utility\Logger;
use Datto\DatabaseAnalyzer\Scanner\Diff;
use Datto\DatabaseAnalyzer\Scanner\Mapper;
use Datto\DatabaseAnalyzer\Scanner\Scan;
use Datto\DatabaseAnalyzer\Scanner\Updater;
use Datto\DatabaseAnalyzer\Documentation\Generator;
require __DIR__ . '/autoload.php';
require __DIR__ . '/vendor/autoload.php';
$configurationFilePath = __DIR__ . '/configuration.ini';
$logger = new Logger('database-analyzer');
$filesystem = new Filesystem();
$settings = new Configuration($filesystem->read($configurationFilePath));
$tableCatalog = $settings->getSetting('tableCatalog');
$whitelist = $settings->getSetting('whitelist');
$documentationDirectory = $settings->getSetting('outputPath');
$scanFile = $settings->getSetting('cachePath');
$mysql = new Mysql($settings);
$database = new Database($mysql->getPdo());
$queries = new DatabaseQueries($database);
$mapper = new Mapper($queries, $tableCatalog, $logger);
$updater = new Updater($filesystem, $settings, $logger);
$generator = new Generator($filesystem, $documentationDirectory);
$logger->info("Mapping the database...");
$scan = $mapper->map($whitelist);
$logger->info("Map complete.");
if (file_exists($scanFile)) {
$logger->info("Transferring stored values...");
// Sample only changed columns.
$oldScan = $filesystem->read($scanFile);
$oldScan = json_decode($oldScan, true);
$oldScan = new Scan($oldScan);
$scan = Diff::transferOldValues($oldScan, $scan);
}
$newScan = $updater->update($scan);
$newScanJson = json_encode($newScan->getScan(), JSON_PRETTY_PRINT);
$filesystem->write($scanFile, $newScanJson);
$logger->info("Generating documentation files...");
$generator->generate($newScan);
$logger->info("Documentation generation complete.");