+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.");
+ }
+ $sSetup = 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.");
+ }