Ejemplo n.º 1
0
 public static function validateConfiguration()
 {
     global $CORE_LOCAL;
     /**
       Opposite of normal. Load the parameters table values
       first, then include ini.php second. If the resulting
       $CORE_LOCAL does not match the paramters table, that
       means ini.php overwrote a setting with a different
       value.
     */
     CoreState::loadParams();
     include dirname(__FILE__) . '/../ini.php';
     $dbc = Database::pDataConnect();
     /**
       Again backwards. Check lane-specific parameters first
     */
     $parameters = new \COREPOS\pos\lib\models\op\ParametersModel($dbc);
     $parameters->store_id(0);
     $parameters->lane_id($CORE_LOCAL->get('laneno'));
     $checked = array();
     $wrong = array();
     foreach ($parameters->find() as $param) {
         $p_value = $param->materializeValue();
         $checked[$param->param_key()] = true;
         $i_value = $CORE_LOCAL->get($param->param_key());
         if (is_numeric($i_value) && is_numeric($p_value) && $i_value == $p_value) {
             // allow loose comparison on numbers
             // i.e., permit integer 1 equal string '1'
             continue;
         }
         if ($p_value !== $i_value) {
             printf('<span style="color:red;">Setting mismatch for</span>
                 <a href="" onclick="$(this).next().toggle(); return false;">%s</a>
                 <span style="display:none;"> parameters says %s, ini.php says %s</span></p>', $param->param_key(), print_r($p_value, true), print_r($i_value, true));
             $wrong[$param->param_key()] = $p_value;
         }
     }
     /**
       Now check global parameters
     */
     $parameters->reset();
     $parameters->store_id(0);
     $parameters->lane_id(0);
     foreach ($parameters->find() as $param) {
         if (isset($checked[$param->param_key()])) {
             // setting has a lane-specific parameters
             // value. no need to check this one.
             continue;
         }
         $p_value = $param->materializeValue();
         $i_value = $CORE_LOCAL->get($param->param_key());
         if (is_numeric($i_value) && is_numeric($p_value) && $i_value == $p_value) {
             // allow loose comparison on numbers
             // i.e., permit integer 1 equal string '1'
             continue;
         }
         if ($p_value !== $i_value) {
             printf('<p>Setting mismatch for 
                 <a href="" onclick=$(this).next.toggle();return false;">%s</a>
                 <span style="display:none;"> parameters says %s, ini.php says %s</span></p>', $param->param_key(), print_r($p_value, true), print_r($i_value, true));
             $wrong[$param->param_key()] = $p_value;
         }
     }
     /**
       Finally, re-save any conflicting values.
       This should rewrite them in ini.php if that
       file is writable.
     */
     foreach ($wrong as $key => $value) {
         self::paramSave($key, $value);
     }
 }
Ejemplo n.º 2
0
 public static function loadParams()
 {
     $db = Database::pDataConnect();
     // newer & optional table. should not fail
     // if it's missing
     if (!$db->table_exists('parameters')) {
         return;
     }
     // load global settings first
     $parameters = new \COREPOS\pos\lib\models\op\ParametersModel($db);
     $parameters->lane_id(0);
     $parameters->store_id(0);
     foreach ($parameters->find() as $global) {
         $key = $global->param_key();
         $value = $global->materializeValue();
         CoreLocal::set($key, $value);
     }
     // apply local settings next
     // with any overrides that occur
     $parameters->reset();
     $parameters->lane_id(CoreLocal::get('laneno'));
     $parameters->store_id(0);
     foreach ($parameters->find() as $local) {
         $key = $local->param_key();
         $value = $local->materializeValue();
         CoreLocal::set($key, $value);
     }
 }