forked from spotweb/spotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecreate-collections.php
74 lines (63 loc) · 2.47 KB
/
recreate-collections.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
<?php
error_reporting(2147483647);
/*
* We need loads of memory to make sure we can cache everything, preventing
* us from going to the database too often
*/
ini_set('memory_limit', '2048M');
function displayProgress($type, $startingPoint, $increment) {
if ($type == 'start') {
echo "Creating collection from spots " . ($startingPoint) . ' to ' . ($startingPoint + $increment) . ', ';;
} elseif ($type == 'finish') {
echo "done. " . PHP_EOL;
} // elseif
} // displayProgress
try {
/*
* If we are run from another directory, try to change the current
* working directory to a directory the script is in
*/
if (@!file_exists(getcwd() . '/' . basename($argv[0]))) {
chdir(dirname(__FILE__));
} # if
require_once "lib/SpotClassAutoload.php";
SpotClassAutoload::register();
require_once "lib/Bootstrap.php";
/*
* Create a DAO factory. We cannot use the bootstrapper here,
* because it validates for a valid settings etc. version.
*/
$bootstrap = new Bootstrap();
list($settings, $daoFactory, $req) = $bootstrap->boot();
# Initialize commandline arguments
SpotCommandline::initialize(array('clean'), array('clean' => false));
# Truncate the current collections tables, and reset all collection id's
if (SpotCommandline::get('clean')) {
$dbConnection = $daoFactory->getConnection();
echo "Cleaning up all existing collections, ";
$dbConnection->rawExec('UPDATE spots SET collectionid = NULL WHERE collectionid IS NOT NULL');
$dbConnection->rawExec('TRUNCATE collections');
$dbConnection->rawExec('TRUNCATE mastercollections');
echo "done.". PHP_EOL;
} // if
/* Load the complete collection cache in memory */
echo "Loading all existing collections in memory, ";
$daoFactory->getCollectionsDao()->loadCollectionCache(array());
echo "done" . PHP_EOL;
/* And start creating ocllections */
$svcCreateColl= new Services_Collections_Create($daoFactory);
$svcCreateColl->createCollections(0, 'displayProgress');
/*
* And actually start updating or creating the schema and settings
*/
echo "Done creating collections" . PHP_EOL;
}
catch(Exception $x) {
echo PHP_EOL . PHP_EOL;
echo 'SpotWeb crashed' . PHP_EOL . PHP_EOL;
echo "Creation of collections failed:" . PHP_EOL;
echo " " . $x->getMessage() . PHP_EOL;
echo PHP_EOL . PHP_EOL;
echo $x->getTraceAsString();
die(1);
} # catch