+if ($aResult['init-updates']) {
+ // sanity check that the replication URL is correct
+ $sBaseState = file_get_contents(CONST_Replication_Url.'/state.txt');
+ if ($sBaseState === false) {
+ echo "\nCannot find state.txt file at the configured replication URL.\n";
+ echo "Does the URL point to a directory containing OSM update data?\n\n";
+ fail('replication URL not reachable.');
+ }
+ // sanity check for pyosmium-get-changes
+ if (!CONST_Pyosmium_Binary) {
+ echo "\nCONST_Pyosmium_Binary not configured.\n";
+ echo "You need to install pyosmium and set up the path to pyosmium-get-changes\n";
+ echo "in your local settings file.\n\n";
+ fail('CONST_Pyosmium_Binary not configured');
+ }
+ $aOutput = 0;
+ $sCmd = CONST_Pyosmium_Binary.' --help';
+ exec($sCmd, $aOutput, $iRet);
+ if ($iRet != 0) {
+ echo "Cannot execute pyosmium-get-changes.\n";
+ echo "Make sure you have pyosmium installed correctly\n";
+ echo "and have set up CONST_Pyosmium_Binary to point to pyosmium-get-changes.\n";
+ fail('pyosmium-get-changes not found or not usable');
+ }
+ if (!$aResult['no-update-functions']) {
+ $sSetup ='@PHP_BIN@ '. CONST_InstallPath.'/utils/setup.php';
+ $iRet = -1;
+ passthru($sSetup.' --create-functions --enable-diff-updates', $iRet);
+ if ($iRet != 0) {
+ fail('Error running setup script');
+ }
+ }
+
+ $sDatabaseDate = getDatabaseDate($oDB);
+ if ($sDatabaseDate === false) {
+ fail('Cannot determine date of database.');
+ }
+ $sWindBack = strftime('%Y-%m-%dT%H:%M:%SZ', strtotime($sDatabaseDate) - (3*60*60));
+
+ // get the appropriate state id
+ $aOutput = 0;
+ $sCmd = CONST_Pyosmium_Binary.' -D '.$sWindBack.' --server '.CONST_Replication_Url;
+ exec($sCmd, $aOutput, $iRet);
+ if ($iRet != 0 || $aOutput[0] == 'None') {
+ fail('Error running pyosmium tools');
+ }
+
+ pg_query($oDB->connection, 'TRUNCATE import_status');
+ $sSQL = "INSERT INTO import_status (lastimportdate, sequence_id, indexed) VALUES('";
+ $sSQL .= $sDatabaseDate."',".$aOutput[0].', true)';
+ if (!pg_query($oDB->connection, $sSQL)) {
+ fail('Could not enter sequence into database.');
+ }
+
+ echo "Done. Database updates will start at sequence $aOutput[0] ($sWindBack)\n";
+}
+
+if ($aResult['check-for-updates']) {
+ $aLastState = chksql($oDB->getRow('SELECT sequence_id FROM import_status'));
+
+ if (!$aLastState['sequence_id']) {
+ fail('Updates not set up. Please run ./utils/update.php --init-updates.');
+ }
+
+ system(CONST_BasePath.'/utils/check_server_for_updates.py '.CONST_Replication_Url.' '.$aLastState['sequence_id'], $iRet);
+ exit($iRet);
+}
+
+if (isset($aResult['import-diff']) || isset($aResult['import-file'])) {
+ // import diffs and files directly (e.g. from osmosis --rri)
+ $sNextFile = isset($aResult['import-diff']) ? $aResult['import-diff'] : $aResult['import-file'];