Esempio n. 1
0
 public static function queuesync($control)
 {
     // Send / receive only works in Client mode.
     if (!Filter_Client::enabled()) {
         return;
     }
     // Deal with a numerical minute to find out whether it's time to automatically sync.
     if (is_numeric($control)) {
         $database_config_general = Database_Config_General::getInstance();
         $repeat = $database_config_general->getRepeatSendReceive();
         // Sync every hour.
         if ($repeat == 1) {
             $control = $control % 60;
             if ($control == 0) {
                 $control = true;
             }
         }
         // Sync every five minutes.
         if ($repeat == 2) {
             $control = $control % 5;
             if ($control == 0) {
                 $control = true;
             }
         }
     }
     // Send and receive: It is time now, or it is manual.
     if ($control === true) {
         // Only queue the sync tasks if none are running at the moment.
         if (SendReceive_Logic::syncqueued()) {
             $database_logs = Database_Logs::getInstance();
             $database_logs->log("Not scheduling sync tasks, because the previous ones have not yet finished");
         } else {
             Tasks_Logic::queue(Tasks_Logic::PHP, array(__DIR__ . "/sendnotes.php"));
             Tasks_Logic::queue(Tasks_Logic::PHP, array(__DIR__ . "/sendbibles.php"));
             Tasks_Logic::queue(Tasks_Logic::PHP, array(__DIR__ . "/sendsettings.php"));
             Tasks_Logic::queue(Tasks_Logic::PHP, array(__DIR__ . "/externalresources.php"));
             Tasks_Logic::queue(Tasks_Logic::PHP, array(__DIR__ . "/usfmresources.php"));
         }
     }
 }
Esempio n. 2
0
if (isset($_GET['runbible'])) {
    SendReceive_Logic::queuebible($bible);
    $view->view->successbible = Locale_Translate::_("Will send and receive.");
}
if (isset($_GET['repeatbible'])) {
    $database_config_bible->setRepeatSendReceive($bible, !$database_config_bible->getRepeatSendReceive($bible));
}
$view->view->repeatbible = $database_config_bible->getRepeatSendReceive($bible);
if ($database_config_bible->getRemoteRepositoryUrl($bible) == "") {
    $view->view->errorbible = Locale_Translate::_("Collaboration has not been set up for this Bible");
}
if (isset($_GET['runsync'])) {
    if (SendReceive_Logic::syncqueued()) {
        $view->view->successnotes = Locale_Translate::_("Still sending and receiving from the last time.");
    } else {
        SendReceive_Logic::queuesync(true);
        $view->view->successnotes = Locale_Translate::_("Will send and receive.");
    }
}
$view->view->client = Filter_Client::enabled();
if (isset($_GET['repeatsync'])) {
    $repeatsync = $_GET['repeatsync'];
    if (!is_numeric($repeatsync)) {
        $repeatsync = 0;
    }
    if ($repeatsync < 0) {
        $repeatsync = 0;
    }
    if ($repeatsync > 2) {
        $repeatsync = 2;
    }
Esempio n. 3
0
function enable_client($username, $password, $level)
{
    // Enable client mode upon a successful connection.
    Filter_Client::set(true);
    // Remove all users from the database, and add the current one.
    remove_all_users();
    $database_users = Database_Users::getInstance();
    $database_users->addNewUser($username, $password, $level, "");
    // Clear all pending note actions and Bible actions and settings updates.
    $database_noteactions = Database_NoteActions::getInstance();
    $database_bibleactions = Database_BibleActions::getInstance();
    $database_config_user = Database_Config_User::getInstance();
    $session_logic = Session_Logic::getInstance();
    $database_noteactions->clear();
    $database_noteactions->create();
    $database_bibleactions->clear();
    $database_bibleactions->create();
    $session_logic->setUsername($username);
    $database_config_user->setUpdatedSettings(array());
    // Set it repeats sync every so often.
    $database_config_general = Database_Config_General::getInstance();
    $database_config_general->setRepeatSendReceive(2);
    // Schedule a sync operation straight-away.
    SendReceive_Logic::queuesync(true);
}
Esempio n. 4
0
// The order is such that all information generated is as recent as possible.
// More important tasks are done first, and the less important ones at the end.
// This leads to an order as visible in the code below.
// Sending and receiving Bibles to and from the git repository.
// On a production website running on an inexpensive virtual private server
// with 512 Mbyte of memory and a fast network connection,
// sending and receiving two Bibles takes more than 15 minutes when there are many changes.
if (!$client) {
    $sendreceive = $hour == 0 && $minute == 6;
    $repeat = $minute % 5 == 0;
    if ($sendreceive || $repeat) {
        SendReceive_Logic::queueAll($sendreceive);
    }
}
// Client sends/receives Bibles and Consultation.
SendReceive_Logic::queuesync($minute);
// Deal with the changes in the Bible made per user.
// Deal with notifications for the daily changes in the Bibles.
// This takes a few minutes on a production machine with two Bibles and changes in several chapters.
if (!$client) {
    if ($hour == 0 && $minute == 20) {
        Changes_Logic::start();
    }
}
// Comb through the git log and add the changes to the history.
if (!$client) {
    if ($hour == 0 && $minute == 30) {
        $directory = dirname(dirname(__FILE__)) . "/changes";
        Tasks_Logic::queue(Tasks_Logic::PHP, array("{$directory}/git.php"));
        unset($directory);
    }