*/
chdir(realpath(dirname(__FILE__)));
require_once '../config/dmsDefaults.php';
/*
Script checks if open office is running, if it isn't then it attempts to start it.
Windows Vista always returns false if we try and check the host and port
so for windows we use the win32 service status checks.
*/
// Check if the calling function requires a return value
$sGiveOutput = isset($argv[1]) && $argv[1] == 'output' ? true : false;
// Check indexed document count
// If the number of indexed documents is greater than the set amount, restart open office
// this clears open office's memory usage
$resetPoint = 50;
// todo: put in config
$count = Indexer::getIndexedDocumentCount();
$restartOO = false;
if ($count > $resetPoint) {
    $restartOO = true;
    // reset the count
    Indexer::updateIndexedDocumentCount(0);
    $default->log->debug('Check Open Office Task: Restarting open office.');
}
// First we check the host:port to see if open office is running
$sCheckOO = SearchHelper::checkOpenOfficeAvailablity();
if (empty($sCheckOO) && !$restartOO) {
    // If the check returns empty then it is available on that port so we exit
    if ($sGiveOutput) {
        echo 1;
    }
    exit;
 private static function incrementCount()
 {
     // Get count from system settings
     $count = Indexer::getIndexedDocumentCount();
     $count = (int) $count + 1;
     Indexer::updateIndexedDocumentCount($count);
 }