Skip to content
Snippets Groups Projects
load_process_event_stack.php 3.54 KiB
Newer Older
  • Learn to ignore specific revisions
  • Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    <?php
    
    
    /**
     * Copyright Maarch since 2008 under licence GPLv3.
     * See LICENCE.txt file at the root folder for more details.
     * This file is part of Maarch software.
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
     */
    
    /**
     * @brief process the event stack
     *
     * @file
     * @author  Cyril Vazquez  <dev@maarch.org>
     * @date $date$
     * @version $Revision$
     * @ingroup notification
     */
    
    /**
    * @brief  Class to include the file error
    *
    */
    class IncludeFileError extends Exception
    {
    
        public function __construct($file)
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        {
            $this->file = $file;
            parent :: __construct('Include File \'$file\' is missing!', 1);
        }
    }
    
    // Globals variables definition
    
    $GLOBALS['batchName']    = 'process_event_stack';
    $GLOBALS['wb']           = '';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    $totalProcessedResources = 0;
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    // Load tools
    include('batch_tools.php');
    
    
    $options = getopt("c:n:", ["config:", "notif:"]);
    if (empty($options['c']) && empty($options['config'])) {
        print("Configuration file missing\n");
        exit(101);
    } elseif (!empty($options['c']) && empty($options['config'])) {
        $options['config'] = $options['c'];
        unset($options['c']);
    }
    if (empty($options['n']) && empty($options['notif'])) {
        print("Notification id missing\n");
        exit(102);
    } elseif (!empty($options['n']) && empty($options['notif'])) {
        $options['notif'] = $options['n'];
        unset($options['n']);
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    }
    
    $txt = '';
    foreach (array_keys($options) as $key) {
        if (isset($options[$key]) && $options[$key] == false) {
            $txt .= $key . '=false,';
        } else {
            $txt .= $key . '=' . $options[$key] . ',';
        }
    }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    $GLOBALS['configFile'] = $options['config'];
    
    $notificationId = $options['notif'];
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    
    print("Load xml config file:" . $GLOBALS['configFile'] . "\n");
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    // Tests existence of config file
    if (!file_exists($GLOBALS['configFile'])) {
    
        print(
            "Configuration file " . $GLOBALS['configFile']
            . " does not exist\n"
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        );
        exit(102);
    }
    // Loading config file
    
    print("Load xml config file:" . $GLOBALS['configFile'] . "\n");
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    $xmlconfig = simplexml_load_file($GLOBALS['configFile']);
    
    
    if ($xmlconfig == false) {
    
        print("Error on loading config file:" . $GLOBALS['configFile'] . "\n");
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        exit(103);
    }
    
    // Load config
    
    $config          = $xmlconfig->CONFIG;
    
    $maarchDirectory = (string)$config->MaarchDirectory;
    
    $customID        = (string)$config->customID;
    $customIDPath    = '';
    
    
    if ($customID <> '') {
    
        $customIDPath = $customID . '_';
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    chdir($maarchDirectory);
    
    $maarchUrl  = (string)$config->MaarchUrl;
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    
    
    $GLOBALS['customId']  = $customID;
    
    $GLOBALS['batchDirectory'] = $maarchDirectory . 'modules'
                               . DIRECTORY_SEPARATOR . 'notifications'
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                               . DIRECTORY_SEPARATOR . 'batch';
    
    set_include_path(get_include_path() . PATH_SEPARATOR . $maarchDirectory);
    
    try {
    
        Bt_myInclude('vendor/autoload.php');
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    } catch (IncludeFileError $e) {
    
        Bt_writeLog(['level' => 'ERROR', 'message' => 'Problem with the php include path:' .$e .' '. get_include_path()]);
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        exit();
    }
    
    
    \SrcCore\models\DatabasePDO::reset();
    
    new \SrcCore\models\DatabasePDO(['customId' => $customID]);
    
    $GLOBALS['errorLckFile'] = $GLOBALS['batchDirectory'] . DIRECTORY_SEPARATOR
                             . $customIDPath . $GLOBALS['batchName'] . '_error.lck';
    $GLOBALS['lckFile'] = $GLOBALS['batchDirectory'] . DIRECTORY_SEPARATOR
                        . $customIDPath . $GLOBALS['batchName'] . '.lck';
                        
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
    if (file_exists($GLOBALS['errorLckFile'])) {
    
        Bt_writeLog(['level' => 'ERROR', 'message' => 'Error persists, please solve this before launching a new batch']);
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
        exit(13);
    }
    
    Bt_getWorkBatch();