Exemplo n.º 1
0
 /**
  * Get all defined environment variables.
  *
  * @return array
  */
 public static function getVars()
 {
     if (!is_array(static::$vars)) {
         $path = static::path("data/env.json");
         try {
             $vars = Json::decodeFromFile($path);
         } catch (\Exception $e) {
             $vars = [];
         }
         static::$vars = Helper::toArray($vars);
     }
     return static::$vars;
 }
Exemplo n.º 2
0
 /**
  * Lock some tables for exlusive write access
  * But allow read access to other processes
  */
 public function lockTables($tables)
 {
     /**
      * Unlock any previously locked tables
      * This is done to provide consistency across different modes, as mysql only allows one single lock over multiple tables
      * Also the odbc only allows all locks to be released, not individual tables. So it makes sense to force the batching of lock/unlock operations
      */
     $this->unlockTables();
     $tables = Helper::toArray($tables);
     if ($this->mode == "odbc") {
         foreach ($tables as $table) {
             $table = $this->getTableName($table);
             $query = "LOCK TABLE " . $table . " IN EXCLUSIVE MODE ALLOW READ";
             $this->query($query);
         }
         # If none of the locks failed then report success
         return true;
     }
     foreach ($tables as &$table) {
         $table = $this->getTableName($table);
     }
     unset($table);
     if ($this->mode == "mysql") {
         $query = "LOCK TABLES " . implode(",", $tables) . " WRITE";
         return $this->query($query);
     }
     if (in_array($this->mode, ["postgres", "redshift"], true)) {
         $query = "LOCK TABLE " . implode(",", $tables) . " IN EXCLUSIVE MODE";
         return $this->query($query);
     }
     throw new \Exception("lockTables() not supported in this mode (" . $this->mode . ")");
 }