Merged in bugfix/HOR-4532 (pull request #6461)
HOR-4532 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
@@ -68,11 +68,11 @@ function lookup($target)
|
|||||||
try {
|
try {
|
||||||
switch ($driver) {
|
switch ($driver) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
if ($link = mysqli_connect(DB_HOST, DB_USER, DB_PASS)) {
|
$results = \Illuminate\Support\Facades\DB::select(DB::raw("select version()"));
|
||||||
$v = mysqli_get_server_info($link);
|
|
||||||
} else {
|
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $results[0]->{'version()'}, $version);
|
||||||
throw new Exception(mysqli_error($link));
|
|
||||||
}
|
$v = $version[0];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return (isset($v))?$v:'none';
|
return (isset($v))?$v:'none';
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,83 +1,53 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
use Illuminate\Database\QueryException;
|
||||||
* class.database_base.php
|
use Illuminate\Support\Facades\DB;
|
||||||
*
|
|
||||||
* @package gulliver.system
|
|
||||||
*
|
|
||||||
* ProcessMaker Open Source Edition
|
|
||||||
* Copyright (C) 2004 - 2008 Colosa Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
||||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Database Maintenance class
|
* Database Maintenance class
|
||||||
*
|
*
|
||||||
* author Erik A. Ortiz <erik@colosa.com, aortiz.erik@gmail.com>
|
|
||||||
* date May 17th, 2010
|
|
||||||
*
|
*
|
||||||
* @package gulliver.system
|
* @package gulliver.system
|
||||||
*/
|
*/
|
||||||
class DataBaseMaintenance
|
class DataBaseMaintenance
|
||||||
{
|
{
|
||||||
private $host;
|
private $host = null;
|
||||||
private $user;
|
private $user = null;
|
||||||
private $passwd;
|
private $passwd = null;
|
||||||
|
|
||||||
private $link;
|
private $connect = null;
|
||||||
private $dbName;
|
private $dbName = null;
|
||||||
public $result;
|
public $result;
|
||||||
protected $tmpDir;
|
protected $tmpDir = null;
|
||||||
protected $outfile;
|
protected $outfile;
|
||||||
protected $infile;
|
protected $infile;
|
||||||
protected $isWindows;
|
protected $isWindows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __construct
|
* DataBaseMaintenance constructor.
|
||||||
*
|
*
|
||||||
* @param string $host is null
|
* @param string $host
|
||||||
* @param string $user is null
|
* @param string $user
|
||||||
* @param string $passwd is null
|
* @param string $passwd
|
||||||
*
|
*
|
||||||
* @return none
|
|
||||||
*/
|
*/
|
||||||
public function __construct($host = null, $user = null, $passwd = null)
|
public function __construct($host = null, $user = null, $passwd = null)
|
||||||
{
|
{
|
||||||
$this->tmpDir = './';
|
$this->tmpDir = './';
|
||||||
$this->link = null;
|
$this->setConnection(null);
|
||||||
$this->dbName = null;
|
$this->setDbName(null);
|
||||||
$this->isWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
|
$this->isWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
|
||||||
if (isset($host) && isset($user) && isset($passwd)) {
|
$this->setUser($user);
|
||||||
$this->host = $host;
|
$this->setHost($host);
|
||||||
$this->user = $user;
|
$this->setPasswd($passwd);
|
||||||
$this->passwd = $passwd;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setUser
|
* setUser
|
||||||
*
|
*
|
||||||
* @param string $user
|
* @param string $user
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
*/
|
||||||
public function setUser($user)
|
public function setUser($user)
|
||||||
{
|
{
|
||||||
@@ -85,11 +55,9 @@ class DataBaseMaintenance
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setPasswd
|
* Set Password
|
||||||
*
|
*
|
||||||
* @param string $passwd
|
* @param string $passwd
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
*/
|
||||||
public function setPasswd($passwd)
|
public function setPasswd($passwd)
|
||||||
{
|
{
|
||||||
@@ -97,11 +65,9 @@ class DataBaseMaintenance
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setHost
|
* Set Host
|
||||||
*
|
*
|
||||||
* @param string $host
|
* @param string $host
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
*/
|
||||||
public function setHost($host)
|
public function setHost($host)
|
||||||
{
|
{
|
||||||
@@ -109,11 +75,9 @@ class DataBaseMaintenance
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setTempDir
|
* Set TempDir
|
||||||
*
|
*
|
||||||
* @param string $tmpDir
|
* @param string $tmpDir
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
*/
|
||||||
public function setTempDir($tmpDir)
|
public function setTempDir($tmpDir)
|
||||||
{
|
{
|
||||||
@@ -124,7 +88,64 @@ class DataBaseMaintenance
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getTempDir
|
* Set Db Name
|
||||||
|
*
|
||||||
|
* @param $dbName
|
||||||
|
*/
|
||||||
|
public function setDbName($dbName)
|
||||||
|
{
|
||||||
|
$this->dbName = $dbName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Connection
|
||||||
|
*
|
||||||
|
* @param $name
|
||||||
|
*/
|
||||||
|
public function setConnection($name)
|
||||||
|
{
|
||||||
|
$this->connect = 'DB_' . $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get User
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUser()
|
||||||
|
{
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Password
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPasswd()
|
||||||
|
{
|
||||||
|
return $this->passwd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Host
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getHost()
|
||||||
|
{
|
||||||
|
return $this->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Name Connection
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getConnect()
|
||||||
|
{
|
||||||
|
return $this->connect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get TempDir
|
||||||
*
|
*
|
||||||
* @return $this->tmpDir
|
* @return $this->tmpDir
|
||||||
*/
|
*/
|
||||||
@@ -134,116 +155,74 @@ class DataBaseMaintenance
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* status
|
* Get Name DB
|
||||||
*
|
*
|
||||||
* @return $this->link
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function status()
|
public function getDbName()
|
||||||
{
|
{
|
||||||
return $$this->link;
|
return $this->dbName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* connect
|
* Connect to DB
|
||||||
*
|
*
|
||||||
* @param string $dbname is null
|
* @param string $dbName
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
|
||||||
public function connect($dbname = null)
|
|
||||||
{
|
|
||||||
if ($this->link != null) {
|
|
||||||
mysqli_close($this->link);
|
|
||||||
$this->link = null;
|
|
||||||
}
|
|
||||||
if (isset($dbname)) {
|
|
||||||
$this->dbName = $dbname;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->link = mysqli_connect($this->host, $this->user, $this->passwd, $this->dbName);
|
|
||||||
if (!$this->link) {
|
|
||||||
throw new Exception("Couldn't connect to host {$this->host} with user {$this->user}");
|
|
||||||
}
|
|
||||||
mysqli_query($this->link, "SET NAMES 'utf8';");
|
|
||||||
mysqli_query($this->link, "SET FOREIGN_KEY_CHECKS=0;");
|
|
||||||
|
|
||||||
if ($this->dbName != null) {
|
|
||||||
$this->selectDataBase($this->dbName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* setDbName
|
|
||||||
*
|
|
||||||
* @param string $dbname is null
|
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
|
||||||
public function setDbName($dbname)
|
|
||||||
{
|
|
||||||
$this->dbName = $dbname;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* selectDataBase
|
|
||||||
*
|
|
||||||
* @param string $dbname
|
|
||||||
* @param $dbname
|
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function selectDataBase($dbname)
|
public function connect($dbName)
|
||||||
{
|
{
|
||||||
$this->setDbName($dbname);
|
try {
|
||||||
if (!mysqli_select_db($this->link, $this->dbName)) {
|
$this->setConnection($dbName);
|
||||||
throw new Exception("Couldn't select database $dbname");
|
$this->setDbName($dbName);
|
||||||
|
InstallerModule::setNewConnection(
|
||||||
|
$this->getConnect(),
|
||||||
|
$this->getHost(),
|
||||||
|
$this->getUser(),
|
||||||
|
$this->getPasswd(),
|
||||||
|
$this->getDbName(),
|
||||||
|
'');
|
||||||
|
|
||||||
|
DB::connection($this->getConnect())
|
||||||
|
->statement("SET NAMES 'utf8'");
|
||||||
|
DB::connection($this->getConnect())
|
||||||
|
->statement('SET FOREIGN_KEY_CHECKS=0');
|
||||||
|
|
||||||
|
} catch (QueryException $exception) {
|
||||||
|
throw new Exception("Couldn't connect to host {$this->getHost()} with user {$this->getUser()}" . $exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* query
|
* Query
|
||||||
*
|
*
|
||||||
* @param string $sql
|
* @param string $sql
|
||||||
*
|
*
|
||||||
* @return $aRows
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function query($sql)
|
public function query($sql)
|
||||||
{
|
{
|
||||||
$this->result = mysqli_query($this->link, $sql);
|
try {
|
||||||
if ($this->result) {
|
$result = DB::connection($this->getConnect())
|
||||||
$aRows = [];
|
->select($sql);
|
||||||
while ($aRow = mysqli_fetch_assoc($this->result)) {
|
|
||||||
$aRows[] = $aRow;
|
return $result;
|
||||||
}
|
} catch (QueryException $exception) {
|
||||||
return $aRows;
|
throw new Exception("Couldn't connect to host {$this->getHost()} with user {$this->getUser()}" . $exception->getMessage());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* error
|
* get Tables List
|
||||||
*
|
|
||||||
* @return mysqli_error()
|
|
||||||
*/
|
|
||||||
public function error()
|
|
||||||
{
|
|
||||||
return mysqli_error($this->link);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* getTablesList
|
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getTablesList()
|
public function getTablesList()
|
||||||
{
|
{
|
||||||
$this->result = mysqli_query($this->link, 'SHOW TABLES;');
|
return $this->query('SHOW TABLES');
|
||||||
$rows = [];
|
|
||||||
while ($row = mysqli_fetch_row($this->result)) {
|
|
||||||
$rows[] = $row[0];
|
|
||||||
}
|
|
||||||
return $rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -255,25 +234,26 @@ class DataBaseMaintenance
|
|||||||
*/
|
*/
|
||||||
public function dumpData($table)
|
public function dumpData($table)
|
||||||
{
|
{
|
||||||
$this->outfile = $this->tmpDir . $table . '.dump';
|
try {
|
||||||
|
$this->outfile = $this->tmpDir . $table . '.dump';
|
||||||
|
|
||||||
//if the file exists delete it
|
//if the file exists delete it
|
||||||
if (is_file($this->outfile)) {
|
if (is_file($this->outfile)) {
|
||||||
@unlink($this->outfile);
|
@unlink($this->outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT * INTO OUTFILE '{$this->outfile}' FIELDS TERMINATED BY '\t|\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\t\t\r\r\n' FROM $table";
|
$sql = "SELECT * INTO OUTFILE '{$this->outfile}' FIELDS TERMINATED BY '\t|\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\t\t\r\r\n' FROM $table";
|
||||||
// The mysql_escape_string function has been DEPRECATED as of PHP 5.3.0.
|
|
||||||
// Commented that is not assigned to a variable.
|
DB::connection($this->getConnect())->raw($sql);
|
||||||
// mysql_escape_string("';");
|
|
||||||
if (!@mysqli_query($this->link, $sql)) {
|
return true;
|
||||||
|
} catch (QueryException $exception) {
|
||||||
$ws = (!empty(config('system.workspace'))) ? config('system.workspace') : 'Undefined Workspace';
|
$ws = (!empty(config('system.workspace'))) ? config('system.workspace') : 'Undefined Workspace';
|
||||||
Bootstrap::registerMonolog('MysqlCron', 400, mysqli_error($this->link), ['sql' => $sql], $ws, 'processmaker.log');
|
Bootstrap::registerMonolog('MysqlCron', 400, $exception->getMessage(), ['sql' => $sql], $ws, 'processmaker.log');
|
||||||
$varRes = mysqli_error($this->link) . "\n";
|
$varRes = $exception->getMessage() . "\n";
|
||||||
G::outRes($varRes);
|
G::outRes($varRes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -285,16 +265,20 @@ class DataBaseMaintenance
|
|||||||
*/
|
*/
|
||||||
public function restoreData($backupFile)
|
public function restoreData($backupFile)
|
||||||
{
|
{
|
||||||
$tableName = str_replace('.dump', '', basename($backupFile));
|
try {
|
||||||
$sql = "LOAD DATA INFILE '$backupFile' INTO TABLE $tableName FIELDS TERMINATED BY '\t|\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\t\t\r\r\n'";
|
$tableName = str_replace('.dump', '', basename($backupFile));
|
||||||
if (!@mysqli_query($this->link, $sql)) {
|
$sql = "LOAD DATA INFILE '$backupFile' INTO TABLE $tableName FIELDS TERMINATED BY '\t|\t' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\t\t\r\r\n'";
|
||||||
|
|
||||||
|
DB::connection($this->getConnect())->raw($sql);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (QueryException $exception) {
|
||||||
$ws = (!empty(config("system.workspace"))) ? config("system.workspace") : "Wokspace Undefined";
|
$ws = (!empty(config("system.workspace"))) ? config("system.workspace") : "Wokspace Undefined";
|
||||||
Bootstrap::registerMonolog('MysqlCron', 400, mysqli_error($this->link), ['sql' => $sql], $ws, 'processmaker.log');
|
Bootstrap::registerMonolog('MysqlCron', 400, $exception->getMessage(), ['sql' => $sql], $ws, 'processmaker.log');
|
||||||
$varRes = mysqli_error($this->link) . "\n";
|
$varRes = $exception->getMessage() . "\n";
|
||||||
G::outRes($varRes);
|
G::outRes($varRes);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,24 +286,22 @@ class DataBaseMaintenance
|
|||||||
*
|
*
|
||||||
* @param string $type default value null
|
* @param string $type default value null
|
||||||
*
|
*
|
||||||
* @return none
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function restoreAllData($type = null)
|
public function restoreAllData($type = null)
|
||||||
{
|
{
|
||||||
$aTables = $this->getTablesList();
|
foreach ($this->getTablesList() as $table) {
|
||||||
|
if (isset($type) && $type === 'sql') {
|
||||||
foreach ($aTables as $table) {
|
$this->infile = $this->tmpDir . $table . '.sql';
|
||||||
if (isset($type) && $type == 'sql') {
|
|
||||||
$this->infile = $this->tmpDir . $table . ".sql";
|
|
||||||
if (is_file($this->infile)) {
|
if (is_file($this->infile)) {
|
||||||
$queries = $this->restoreFromSql($this->infile, true);
|
$queries = $this->restoreFromSql($this->infile, true);
|
||||||
if (!isset($queries)) {
|
if (!isset($queries)) {
|
||||||
$queries = "unknown";
|
$queries = 'unknown';
|
||||||
}
|
}
|
||||||
printf("%-59s%20s", "Restored table $table", "$queries queries\n");
|
printf("%-59s%20s", "Restored table $table", "$queries queries\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->infile = $this->tmpDir . $table . ".dump";
|
$this->infile = $this->tmpDir . $table . '.dump';
|
||||||
if (is_file($this->infile)) {
|
if (is_file($this->infile)) {
|
||||||
$this->restoreData($this->infile);
|
$this->restoreData($this->infile);
|
||||||
printf("%20s %s %s\n", 'Restoring data from ', $this->infile, " in table $table");
|
printf("%20s %s %s\n", 'Restoring data from ', $this->infile, " in table $table");
|
||||||
@@ -329,63 +311,27 @@ class DataBaseMaintenance
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* createDb
|
* Create DB
|
||||||
*
|
*
|
||||||
* @param string $dbname
|
* @param string $dbname
|
||||||
* @param string $drop default value false
|
* @param boolean $drop
|
||||||
*
|
*
|
||||||
* @return none
|
* @return bool
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function createDb($dbname, $drop = false)
|
public function createDb($dbname, $drop = false)
|
||||||
{
|
{
|
||||||
if ($drop) {
|
try {
|
||||||
$sql = "DROP DATABASE IF EXISTS $dbname;";
|
if ($drop) {
|
||||||
if (!mysqli_query($this->link, $sql)) {
|
DB::connection($this->getConnect())->statement("DROP DATABASE IF EXISTS $dbname");
|
||||||
throw new Exception(mysqli_error($this->link));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
$sql = "CREATE DATABASE IF NOT EXISTS $dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;";
|
|
||||||
if (!mysqli_query($this->link, $sql)) {
|
|
||||||
throw new Exception(mysqli_error($this->link));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
DB::connection($this->getConnect())->statement("CREATE DATABASE IF NOT EXISTS $dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
|
||||||
* restoreFromSql2
|
|
||||||
*
|
|
||||||
* @param string $sqlfile
|
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
|
||||||
public function restoreFromSql2($sqlfile)
|
|
||||||
{
|
|
||||||
ini_set('memory_limit', '512M');
|
|
||||||
if (!is_file($sqlfile)) {
|
|
||||||
throw new Exception("the $sqlfile doesn't exist!");
|
|
||||||
}
|
|
||||||
$query = file_get_contents($sqlfile);
|
|
||||||
$mysqli = new mysqli($this->host, $this->user, $this->passwd, $this->dbName);
|
|
||||||
|
|
||||||
/* check connection */
|
return true;
|
||||||
if (mysqli_connect_errno()) {
|
} catch (QueryException $exception) {
|
||||||
printf("Connect failed: %s\n", mysqli_connect_error());
|
throw new Exception($exception->getMessage());
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* execute multi query */
|
|
||||||
if ($mysqli->multi_query($query)) {
|
|
||||||
do {
|
|
||||||
/* store first result set */
|
|
||||||
if ($result = $mysqli->store_result()) {
|
|
||||||
while ($row = $result->fetch_row()) {
|
|
||||||
}
|
|
||||||
$result->free();
|
|
||||||
}
|
|
||||||
} while ($mysqli->next_result());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* close connection */
|
|
||||||
$mysqli->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -397,36 +343,36 @@ class DataBaseMaintenance
|
|||||||
*/
|
*/
|
||||||
public function backupDataBase($outfile)
|
public function backupDataBase($outfile)
|
||||||
{
|
{
|
||||||
$password = escapeshellarg($this->passwd);
|
$password = escapeshellarg($this->getPasswd());
|
||||||
|
|
||||||
//On Windows, escapeshellarg() instead replaces percent signs, exclamation
|
//On Windows, escapeshellarg() instead replaces percent signs, exclamation
|
||||||
//marks (delayed variable substitution) and double quotes with spaces and
|
//marks (delayed variable substitution) and double quotes with spaces and
|
||||||
//adds double quotes around the string.
|
//adds double quotes around the string.
|
||||||
//See: http://php.net/manual/en/function.escapeshellarg.php
|
//See: http://php.net/manual/en/function.escapeshellarg.php
|
||||||
if ($this->isWindows) {
|
if ($this->isWindows) {
|
||||||
$password = $this->escapeshellargCustom($this->passwd);
|
$password = $this->escapeshellargCustom($this->getPasswd());
|
||||||
}
|
}
|
||||||
$aHost = explode(':', $this->host);
|
$aHost = explode(':', $this->getHost());
|
||||||
$dbHost = $aHost[0];
|
$dbHost = $aHost[0];
|
||||||
if (isset($aHost[1])) {
|
if (isset($aHost[1])) {
|
||||||
$dbPort = $aHost[1];
|
$dbPort = $aHost[1];
|
||||||
$command = 'mysqldump'
|
$command = 'mysqldump'
|
||||||
. ' --user=' . $this->user
|
. ' --user=' . $this->getUser()
|
||||||
. ' --password=' . $password
|
. ' --password=' . $password
|
||||||
. ' --host=' . $dbHost
|
. ' --host=' . $dbHost
|
||||||
. ' --port=' . $dbPort
|
. ' --port=' . $dbPort
|
||||||
. ' --opt'
|
. ' --opt'
|
||||||
. ' --skip-comments'
|
. ' --skip-comments'
|
||||||
. ' ' . $this->dbName
|
. ' ' . $this->getDbName()
|
||||||
. ' > ' . $outfile;
|
. ' > ' . $outfile;
|
||||||
} else {
|
} else {
|
||||||
$command = 'mysqldump'
|
$command = 'mysqldump'
|
||||||
. ' --host=' . $dbHost
|
. ' --host=' . $dbHost
|
||||||
. ' --user=' . $this->user
|
. ' --user=' . $this->getUser()
|
||||||
. ' --opt'
|
. ' --opt'
|
||||||
. ' --skip-comments'
|
. ' --skip-comments'
|
||||||
. ' --password=' . $password
|
. ' --password=' . $password
|
||||||
. ' ' . $this->dbName
|
. ' ' . $this->getDbName()
|
||||||
. ' > ' . $outfile;
|
. ' > ' . $outfile;
|
||||||
}
|
}
|
||||||
shell_exec($command);
|
shell_exec($command);
|
||||||
@@ -448,21 +394,21 @@ class DataBaseMaintenance
|
|||||||
*/
|
*/
|
||||||
private function escapeshellargCustom($string, $quotes = "")
|
private function escapeshellargCustom($string, $quotes = "")
|
||||||
{
|
{
|
||||||
if ($quotes === "") {
|
if ($quotes === '') {
|
||||||
$quotes = $this->isWindows ? "\"" : "'";
|
$quotes = $this->isWindows ? "\"" : "'";
|
||||||
}
|
}
|
||||||
$n = strlen($string);
|
$n = strlen($string);
|
||||||
$special = ["!", "%", "\""];
|
$special = ["!", "%", "\""];
|
||||||
$substring = "";
|
$substring = '';
|
||||||
$result1 = [];
|
$result1 = [];
|
||||||
$result2 = [];
|
$result2 = [];
|
||||||
for ($i = 0; $i < $n; $i++) {
|
for ($i = 0; $i < $n; $i++) {
|
||||||
if (in_array($string[$i], $special, true)) {
|
if (in_array($string[$i], $special, true)) {
|
||||||
$result2[] = $string[$i];
|
$result2[] = $string[$i];
|
||||||
$result1[] = $substring;
|
$result1[] = $substring;
|
||||||
$substring = "";
|
$substring = '';
|
||||||
} else {
|
} else {
|
||||||
$substring = $substring . $string[$i];
|
$substring .= $string[$i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result1[] = $substring;
|
$result1[] = $substring;
|
||||||
@@ -471,43 +417,47 @@ class DataBaseMaintenance
|
|||||||
for ($i = 0; $i < $n; $i++) {
|
for ($i = 0; $i < $n; $i++) {
|
||||||
$result1[$i] = trim(escapeshellarg($result1[$i]), $quotes);
|
$result1[$i] = trim(escapeshellarg($result1[$i]), $quotes);
|
||||||
if (isset($result2[$i])) {
|
if (isset($result2[$i])) {
|
||||||
$result1[$i] = $result1[$i] . $result2[$i];
|
$result1[$i] .= $result2[$i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//add simple quotes, see escapeshellarg function
|
//add simple quotes, see escapeshellarg function
|
||||||
$newString = $quotes . implode("", $result1) . $quotes;
|
$newString = $quotes . implode('', $result1) . $quotes;
|
||||||
return $newString;
|
return $newString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* restoreFromSql
|
* Restore from sql
|
||||||
*
|
*
|
||||||
* @param string $sqlfile
|
* @param string $sqlFile
|
||||||
|
* @param string $type
|
||||||
*
|
*
|
||||||
* @return boolean false or true
|
* @return boolean false or true
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function restoreFromSql($sqlfile, $type = 'file')
|
public function restoreFromSql($sqlFile, $type = 'file')
|
||||||
{
|
{
|
||||||
ini_set('memory_limit', '64M');
|
ini_set('memory_limit', '64M');
|
||||||
if ($type == 'file' && !is_file($sqlfile)) {
|
if ($type == 'file' && !is_file($sqlFile)) {
|
||||||
throw new Exception("the $sqlfile doesn't exist!");
|
throw new Exception("the $sqlFile doesn't exist!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$metaFile = str_replace('.sql', '.meta', $sqlfile);
|
$metaFile = str_replace('.sql', '.meta', $sqlFile);
|
||||||
|
|
||||||
$queries = 0;
|
$queries = 0;
|
||||||
|
|
||||||
if (is_file($metaFile)) {
|
if (is_file($metaFile)) {
|
||||||
echo "Using $metaFile as metadata.\n";
|
echo "Using $metaFile as metadata.\n";
|
||||||
$fp = fopen($sqlfile, 'rb');
|
$fp = fopen($sqlFile, 'rb');
|
||||||
$fpmd = fopen($metaFile, 'r');
|
$fpmd = fopen($metaFile, 'r');
|
||||||
while ($offset = fgets($fpmd, 1024)) {
|
while ($offset = fgets($fpmd, 1024)) {
|
||||||
$buffer = intval($offset); //reading the size of $oData
|
$buffer = intval($offset); //reading the size of $oData
|
||||||
$query = fread($fp, $buffer); //reading string $oData
|
$query = fread($fp, $buffer); //reading string $oData
|
||||||
$queries += 1;
|
$queries++;
|
||||||
|
|
||||||
if (!mysqli_query($this->link, $query)) {
|
try {
|
||||||
$varRes = mysqli_error($this->link) . "\n";
|
DB::connection($this->getConnect())->raw($query);
|
||||||
|
} catch (QueryException $exception) {
|
||||||
|
$varRes = $exception->getMessage() . "\n";
|
||||||
G::outRes($varRes);
|
G::outRes($varRes);
|
||||||
$varRes = "==>" . $query . "<==\n";
|
$varRes = "==>" . $query . "<==\n";
|
||||||
G::outRes($varRes);
|
G::outRes($varRes);
|
||||||
@@ -516,45 +466,25 @@ class DataBaseMaintenance
|
|||||||
} else {
|
} else {
|
||||||
$queries = null;
|
$queries = null;
|
||||||
try {
|
try {
|
||||||
$mysqli = new mysqli($this->host, $this->user, $this->passwd, $this->dbName);
|
|
||||||
/* check connection */
|
|
||||||
if (mysqli_connect_errno()) {
|
|
||||||
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
if ($type === 'file') {
|
if ($type === 'file') {
|
||||||
$query = file_get_contents($sqlfile);
|
$query = file_get_contents($sqlFile);
|
||||||
} elseif ($type === 'string') {
|
} elseif ($type === 'string') {
|
||||||
$query = $sqlfile;
|
$query = $sqlFile;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trim($query) == "") {
|
if (empty(trim($query))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* execute multi query */
|
try {
|
||||||
if ($mysqli->multi_query($query)) {
|
DB::connection($this->getConnect())->raw($query);
|
||||||
do {
|
} catch (QueryException $exception) {
|
||||||
/* store first result set */
|
throw new Exception($exception->getMessage());
|
||||||
if ($result = $mysqli->store_result()) {
|
|
||||||
while ($row = $result->fetch_row()) {
|
|
||||||
//printf("%s\n", $row[0]);
|
|
||||||
}
|
|
||||||
$result->free();
|
|
||||||
}
|
|
||||||
/* print divider */
|
|
||||||
if ($mysqli->more_results()) {
|
|
||||||
//printf("-----------------\n");
|
|
||||||
}
|
|
||||||
} while ($mysqli->next_result());
|
|
||||||
} else {
|
|
||||||
throw new Exception(mysqli_error($mysqli));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close connection */
|
|
||||||
$mysqli->close();
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
echo $query;
|
echo $query;
|
||||||
$token = strtotime("now");
|
$token = strtotime("now");
|
||||||
@@ -574,19 +504,18 @@ class DataBaseMaintenance
|
|||||||
*/
|
*/
|
||||||
public function getSchemaFromTable($tablename)
|
public function getSchemaFromTable($tablename)
|
||||||
{
|
{
|
||||||
//$tableSchema = "/* Structure for table `$tablename` */\n";
|
try {
|
||||||
//$tableSchema .= "DROP TABLE IF EXISTS `$tablename`;\n\n";
|
$tableSchema = '';
|
||||||
$tableSchema = "";
|
$result = DB::connection($this->getConnect())->select("show create table `$tablename`");
|
||||||
$sql = "show create table `$tablename`; ";
|
|
||||||
$result = mysqli_query($this->link, $sql);
|
if ($result) {
|
||||||
if ($result) {
|
$tableSchema = $result['Create Table'] . ";\n\n";
|
||||||
if ($row = mysqli_fetch_assoc($result)) {
|
|
||||||
$tableSchema .= $row['Create Table'] . ";\n\n";
|
|
||||||
}
|
}
|
||||||
mysqli_free_result($result);
|
|
||||||
} else {
|
} catch (QueryException $exception) {
|
||||||
G::outRes(mysqli_error($this->link));
|
G::outRes($exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tableSchema;
|
return $tableSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* cliUpgrade.php
|
|
||||||
*
|
|
||||||
* ProcessMaker Open Source Edition
|
|
||||||
* Copyright (C) 2011 Colosa Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
||||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
||||||
*
|
|
||||||
* @author Alexandre Rosenfeld <alexandre@colosa.com>
|
|
||||||
* @package workflow-engine-bin-tasks
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use ProcessMaker\Core\System;
|
use ProcessMaker\Core\System;
|
||||||
|
|
||||||
CLI::taskName('upgrade');
|
CLI::taskName('upgrade');
|
||||||
@@ -296,25 +272,24 @@ function run_unify_database($args)
|
|||||||
$metadata["version"] = 1;
|
$metadata["version"] = 1;
|
||||||
|
|
||||||
list($dbHost, $dbUser, $dbPass) = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
|
list($dbHost, $dbUser, $dbPass) = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
|
||||||
$link = mysqli_connect($dbHost, $dbUser, $dbPass);
|
$connectionName = 'UPGRADE';
|
||||||
|
InstallerModule::setNewConnection($connectionName, $dbHost, $dbUser, $dbPass,'', '');
|
||||||
|
|
||||||
foreach ($metadata['databases'] as $db) {
|
foreach ($metadata['databases'] as $db) {
|
||||||
$dbName = $metadata['DB_NAME'];
|
$dbName = $metadata['DB_NAME'];
|
||||||
CLI::logging("+> Restoring {$db['name']} to $dbName database\n");
|
CLI::logging("+> Restoring {$db['name']} to $dbName database\n");
|
||||||
|
|
||||||
$aParameters = array('dbHost'=>$dbHost,'dbUser'=>$dbUser,'dbPass'=>$dbPass);
|
$aParameters = ['dbHost'=>$dbHost,'dbUser'=>$dbUser,'dbPass'=>$dbPass];
|
||||||
|
|
||||||
$restore = $workspace->executeScript($dbName, "$tempDirectory/{$db['name']}.sql", $aParameters, $link);
|
$restore = $workspace->executeScript($dbName, "$tempDirectory/{$db['name']}.sql", $aParameters, $connectionName);
|
||||||
|
|
||||||
if ($restore) {
|
if ($restore) {
|
||||||
CLI::logging("+> Remove {$db['name']} database\n");
|
CLI::logging("+> Remove {$db['name']} database\n");
|
||||||
|
|
||||||
$sql = "DROP DATABASE IF EXISTS {$db['name']};";
|
DB::connection($connectionName)->statement("DROP DATABASE IF EXISTS {$db['name']}");
|
||||||
if (!mysqli_query($link, $sql)) {
|
|
||||||
throw new Exception(mysqli_error($link));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DB::disconnect($connectionName);
|
||||||
|
|
||||||
CLI::logging("Removing temporary files\n");
|
CLI::logging("Removing temporary files\n");
|
||||||
G::rm_dir($tempDirectory);
|
G::rm_dir($tempDirectory);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MultipleFilesBackup
|
* Class MultipleFilesBackup
|
||||||
* create a backup of this workspace
|
* create a backup of this workspace
|
||||||
@@ -20,12 +22,12 @@ class MultipleFilesBackup
|
|||||||
* @filename contains the path and filename of the comppress file(s).
|
* @filename contains the path and filename of the comppress file(s).
|
||||||
* @size got the Max size of the compressed files, by default if the $size less to zero will mantains 1000 Mb as Max size.
|
* @size got the Max size of the compressed files, by default if the $size less to zero will mantains 1000 Mb as Max size.
|
||||||
*/
|
*/
|
||||||
public function MultipleFilesBackup($filename, $size)
|
public function __construct($filename, $size)
|
||||||
{
|
{
|
||||||
if (!empty($filename)) {
|
if (!empty($filename)) {
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
}
|
}
|
||||||
if (!empty($size) && (int) $size > 0) {
|
if (!empty($size) && (int)$size > 0) {
|
||||||
$this->fileSize = $size;
|
$this->fileSize = $size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,6 +93,7 @@ class MultipleFilesBackup
|
|||||||
G::rm_dir($tempDirectory);
|
G::rm_dir($tempDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore from file(s) commpressed by letsBackup function, into a temporary directory
|
/* Restore from file(s) commpressed by letsBackup function, into a temporary directory
|
||||||
* @ filename got the name and path of the compressed file(s), if there are many files with file extention as a numerical series, the extention should be discriminated.
|
* @ filename got the name and path of the compressed file(s), if there are many files with file extention as a numerical series, the extention should be discriminated.
|
||||||
* @ srcWorkspace contains the workspace to be restored.
|
* @ srcWorkspace contains the workspace to be restored.
|
||||||
@@ -162,14 +165,14 @@ class MultipleFilesBackup
|
|||||||
CLI::logging(CLI::warning("> Workspace $backupWorkspace found, but not restoring.") . "\n");
|
CLI::logging(CLI::warning("> Workspace $backupWorkspace found, but not restoring.") . "\n");
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
CLI::logging("> Restoring " . CLI::info($backupWorkspace) . " to " . CLI::info($workspaceName) . "\n");
|
CLI::logging('> Restoring ' . CLI::info($backupWorkspace) . ' to ' . CLI::info($workspaceName) . "\n");
|
||||||
}
|
}
|
||||||
$workspace = new WorkspaceTools($workspaceName);
|
$workspace = new WorkspaceTools($workspaceName);
|
||||||
if ($workspace->workspaceExists()) {
|
if ($workspace->workspaceExists()) {
|
||||||
if ($overwrite) {
|
if ($overwrite) {
|
||||||
CLI::logging(CLI::warning("> Workspace $workspaceName already exist, overwriting!") . "\n");
|
CLI::logging(CLI::warning("> Workspace $workspaceName already exist, overwriting!") . "\n");
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Destination workspace already exist (use -o to overwrite)");
|
throw new Exception('Destination workspace already exist (use -o to overwrite)');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (file_exists($workspace->path)) {
|
if (file_exists($workspace->path)) {
|
||||||
@@ -196,31 +199,35 @@ class MultipleFilesBackup
|
|||||||
list($dbHost, $dbUser, $dbPass) = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
|
list($dbHost, $dbUser, $dbPass) = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
|
||||||
|
|
||||||
CLI::logging("> Connecting to system database in '$dbHost'\n");
|
CLI::logging("> Connecting to system database in '$dbHost'\n");
|
||||||
$link = mysqli_connect($dbHost, $dbUser, $dbPass);
|
|
||||||
mysqli_query($link, "SET NAMES 'utf8';");
|
try {
|
||||||
mysqli_query($link, "SET FOREIGN_KEY_CHECKS=0;");
|
$connectionLestRestore = 'RESTORE';
|
||||||
if (!$link) {
|
InstallerModule::setNewConnection($connectionLestRestore, $dbHost, $dbUser, $dbPass, '', '');
|
||||||
throw new Exception('Could not connect to system database: ' . mysqli_error($link));
|
DB::connection($connectionLestRestore)
|
||||||
|
->statement("SET NAMES 'utf8'");
|
||||||
|
DB::connection($connectionLestRestore)
|
||||||
|
->statement('SET FOREIGN_KEY_CHECKS=0');
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
throw new Exception('Could not connect to system database: ' . $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$onedb = false;
|
||||||
if (strpos($metadata->DB_RBAC_NAME, 'rb_') === false) {
|
if (strpos($metadata->DB_RBAC_NAME, 'rb_') === false) {
|
||||||
$onedb = true;
|
$onedb = true;
|
||||||
} else {
|
|
||||||
$onedb = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$newDBNames = $workspace->resetDBInfo($dbHost, $createWorkspace, $onedb);
|
$newDBNames = $workspace->resetDBInfo($dbHost, $createWorkspace, $onedb);
|
||||||
$aParameters = array('dbHost' => $dbHost, 'dbUser' => $dbUser, 'dbPass' => $dbPass);
|
$aParameters = ['dbHost' => $dbHost, 'dbUser' => $dbUser, 'dbPass' => $dbPass];
|
||||||
|
|
||||||
foreach ($metadata->databases as $db) {
|
foreach ($metadata->databases as $db) {
|
||||||
$dbName = $newDBNames[$db->name];
|
$dbName = $newDBNames[$db->name];
|
||||||
CLI::logging("+> Restoring database {$db->name} to $dbName\n");
|
CLI::logging("+> Restoring database {$db->name} to $dbName\n");
|
||||||
$workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql", $aParameters, 1, $link);
|
$workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql", $aParameters, 1, $connectionLestRestore);
|
||||||
$workspace->createDBUser($dbName, $db->pass, "localhost", $dbName, $link);
|
$workspace->createDBUser($dbName, $db->pass, "localhost", $dbName, $connectionLestRestore);
|
||||||
$workspace->createDBUser($dbName, $db->pass, "%", $dbName, $link);
|
$workspace->createDBUser($dbName, $db->pass, "%", $dbName, $connectionLestRestore);
|
||||||
}
|
}
|
||||||
$workspace->upgradeCacheView(false);
|
$workspace->upgradeCacheView(false);
|
||||||
mysqli_close($link);
|
|
||||||
}
|
}
|
||||||
CLI::logging("Removing temporary files\n");
|
CLI::logging("Removing temporary files\n");
|
||||||
G::rm_dir($tempDirectory);
|
G::rm_dir($tempDirectory);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class Net
|
class Net
|
||||||
{
|
{
|
||||||
public $hostname;
|
public $hostname;
|
||||||
@@ -223,30 +225,20 @@ class Net
|
|||||||
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
|
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
|
||||||
switch ($pDbDriver) {
|
switch ($pDbDriver) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
// Note, we suppress warnings on the connection calls because we want to avoid displaying warning
|
|
||||||
// When utilizing this code in an API call. Otherwise it will return invalid JSON overall.
|
try {
|
||||||
if ($this->db_passwd == '') {
|
InstallerModule::setNewConnection('NET', $this->ip, $this->db_user, $this->db_passwd, $this->db_sourcename, $this->db_port);
|
||||||
$link = @mysqli_connect($this->ip . (($this->db_port != '') && ($this->db_port != 0) ? ':' . $this->db_port : ''), $this->db_user, $this->db_sourcename);
|
$stat->status = 'SUCCESS';
|
||||||
} else {
|
$this->errstr = '';
|
||||||
$link = @mysqli_connect($this->ip . (($this->db_port != '') && ($this->db_port != 0) ? ':' . $this->db_port : ''), $this->db_user, $this->db_passwd, $this->db_sourcename);
|
$this->errno = 0;
|
||||||
}
|
} catch (Exception $exception) {
|
||||||
if ($link) {
|
$this->error = 'MySql connection refused!';
|
||||||
if (mysqli_ping($link)) {
|
$this->errstr = 'NET::MYSQL->The connection was refused';
|
||||||
$stat->status = 'SUCCESS';
|
|
||||||
$this->errstr = "";
|
|
||||||
$this->errno = 0;
|
|
||||||
} else {
|
|
||||||
$this->error = "Lost MySql Connection";
|
|
||||||
$this->errstr = "NET::MYSQL->Lost Connection";
|
|
||||||
$this->errno = 10010;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->error = "MySql connection refused!";
|
|
||||||
$this->errstr = "NET::MYSQL->The connection was refused";
|
|
||||||
$this->errno = 10001;
|
$this->errno = 10001;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
|
//todo
|
||||||
$this->db_port = ($this->db_port == "") ? "5432" : $this->db_port;
|
$this->db_port = ($this->db_port == "") ? "5432" : $this->db_port;
|
||||||
$link = @pg_connect("host='$this->ip' port='$this->db_port' user='$this->db_user' password='$this->db_passwd' dbname='$this->db_sourcename'");
|
$link = @pg_connect("host='$this->ip' port='$this->db_port' user='$this->db_user' password='$this->db_passwd' dbname='$this->db_sourcename'");
|
||||||
if ($link) {
|
if ($link) {
|
||||||
@@ -260,6 +252,7 @@ class Net
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'mssql':
|
case 'mssql':
|
||||||
|
//todo
|
||||||
if ($this->db_instance != "") {
|
if ($this->db_instance != "") {
|
||||||
$str_port = "";
|
$str_port = "";
|
||||||
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
|
||||||
@@ -279,6 +272,7 @@ class Net
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'oracle':
|
case 'oracle':
|
||||||
|
//todo
|
||||||
try {
|
try {
|
||||||
if ($flagTns == 0) {
|
if ($flagTns == 0) {
|
||||||
$this->db_port = ($this->db_port == "" || $this->db_port == 0) ? "1521" : $this->db_port;
|
$this->db_port = ($this->db_port == "" || $this->db_port == 0) ? "1521" : $this->db_port;
|
||||||
@@ -349,28 +343,23 @@ class Net
|
|||||||
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
|
if (isset($this->db_user) && (isset($this->db_passwd) || $this->db_passwd == "") && (isset($this->db_sourcename) || $flagTns == 1)) {
|
||||||
switch ($pDbDriver) {
|
switch ($pDbDriver) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
$link = mysqli_connect($this->ip . (($this->db_port !== '') && ($this->db_port !== 0) ? ':' . $this->db_port : ''), $this->db_user, $this->db_passwd, $this->db_sourcename);
|
try {
|
||||||
$db = mysqli_select_db($link, $this->db_sourcename);
|
$this->errstr = 'NET::MYSQL->The connection was refused';
|
||||||
$this->error = 'MySql connection refused!';
|
$this->errno = 10001;
|
||||||
$this->errstr = 'NET::MYSQL->The connection was refused';
|
$connection = 'NET_' . $this->db_sourcename;
|
||||||
$this->errno = 10001;
|
InstallerModule::setNewConnection($connection, $this->ip, $this->db_user, $this->db_passwd, $this->db_sourcename, $this->db_port);
|
||||||
|
|
||||||
if ($link) {
|
$this->errstr = 'NET::MYSQL->Test query failed';
|
||||||
$this->error = 'The $this->db_sourcename data base does\'n exist!';
|
$this->errno = 10100;
|
||||||
$this->errstr = 'NET::MYSQL->Select data base failed';
|
|
||||||
$this->errno = 10011;
|
$result = DB::connection($connection)->statement('show tables');
|
||||||
if ($db) {
|
if ($result) {
|
||||||
$result = mysqli_query($link, 'show tables;');
|
$stat->status = 'SUCCESS';
|
||||||
$this->error = 'the user $this->db_user doesn\'t have privileges to run queries!';
|
$this->errstr = '';
|
||||||
$this->errstr = 'NET::MYSQL->Test query failed';
|
$this->errno = 0;
|
||||||
$this->errno = 10100;
|
|
||||||
if ($result) {
|
|
||||||
$stat->status = 'SUCCESS';
|
|
||||||
$this->errstr = '';
|
|
||||||
$this->errno = 0;
|
|
||||||
mysqli_free_result($result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$this->error = $exception->getMessage();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'pgsql':
|
case 'pgsql':
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use ProcessMaker\Core\Installer;
|
use ProcessMaker\Core\Installer;
|
||||||
use ProcessMaker\Core\System;
|
use ProcessMaker\Core\System;
|
||||||
use ProcessMaker\Util\FixReferencePath;
|
use ProcessMaker\Util\FixReferencePath;
|
||||||
@@ -751,55 +753,51 @@ class WorkspaceTools
|
|||||||
*/
|
*/
|
||||||
public function getSchema($rbac = false)
|
public function getSchema($rbac = false)
|
||||||
{
|
{
|
||||||
$oDataBase = $this->getDatabase($rbac);
|
$database = $this->getDatabase($rbac);
|
||||||
|
|
||||||
$aOldSchema = [];
|
$oldSchema = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$oDataBase->iFetchType = MYSQLI_NUM;
|
$database->iFetchType = MYSQLI_NUM;
|
||||||
$oDataset1 = $oDataBase->executeQuery($oDataBase->generateShowTablesSQL());
|
$result = $database->executeQuery($database->generateShowTablesSQL());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$oDataBase->logQuery($e->getmessage());
|
$database->logQuery($e->getmessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//going thru all tables in current WF_ database
|
//going thru all tables in current WF_ database
|
||||||
while ($aRow1 = $oDataBase->getRegistry($oDataset1)) {
|
foreach ($result as $table) {
|
||||||
$aPrimaryKeys = [];
|
$table = strtoupper($table);
|
||||||
$sTable = strtoupper($aRow1[0]);
|
|
||||||
|
|
||||||
//get description of each table, ( column and primary keys )
|
//get description of each table, ( column and primary keys )
|
||||||
//$oDataset2 = $oDataBase->executeQuery( $oDataBase->generateDescTableSQL($aRow1[0]) );
|
$database->iFetchType = MYSQLI_ASSOC;
|
||||||
$oDataset2 = $oDataBase->executeQuery($oDataBase->generateDescTableSQL($sTable));
|
$description = $database->executeQuery($database->generateDescTableSQL($table));
|
||||||
$aOldSchema[$sTable] = [];
|
$oldSchema[$table] = [];
|
||||||
$oDataBase->iFetchType = MYSQLI_ASSOC;
|
foreach ($description as $field) {
|
||||||
while ($aRow2 = $oDataBase->getRegistry($oDataset2)) {
|
$oldSchema[$table][$field['Field']]['Field'] = $field['Field'];
|
||||||
$aOldSchema[$sTable][$aRow2['Field']]['Field'] = $aRow2['Field'];
|
$oldSchema[$table][$field['Field']]['Type'] = $field['Type'];
|
||||||
$aOldSchema[$sTable][$aRow2['Field']]['Type'] = $aRow2['Type'];
|
$oldSchema[$table][$field['Field']]['Null'] = $field['Null'];
|
||||||
$aOldSchema[$sTable][$aRow2['Field']]['Null'] = $aRow2['Null'];
|
$oldSchema[$table][$field['Field']]['Default'] = $field['Default'];
|
||||||
$aOldSchema[$sTable][$aRow2['Field']]['Default'] = $aRow2['Default'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//get indexes of each table SHOW INDEX FROM `ADDITIONAL_TABLES`; -- WHERE Key_name <> 'PRIMARY'
|
//get indexes of each table SHOW INDEX FROM `ADDITIONAL_TABLES`; -- WHERE Key_name <> 'PRIMARY'
|
||||||
$oDataset2 = $oDataBase->executeQuery($oDataBase->generateTableIndexSQL($aRow1[0]));
|
$description = $database->executeQuery($database->generateTableIndexSQL($table));
|
||||||
$oDataBase->iFetchType = MYSQLI_ASSOC;
|
foreach ($description as $field) {
|
||||||
while ($aRow2 = $oDataBase->getRegistry($oDataset2)) {
|
if (!isset($oldSchema[$table]['INDEXES'])) {
|
||||||
if (!isset($aOldSchema[$sTable]['INDEXES'])) {
|
$oldSchema[$table]['INDEXES'] = [];
|
||||||
$aOldSchema[$sTable]['INDEXES'] = [];
|
|
||||||
}
|
}
|
||||||
if (!isset($aOldSchema[$sTable]['INDEXES'][$aRow2['Key_name']])) {
|
if (!isset($oldSchema[$table]['INDEXES'][$field['Key_name']])) {
|
||||||
$aOldSchema[$sTable]['INDEXES'][$aRow2['Key_name']] = [];
|
$oldSchema[$table]['INDEXES'][$field['Key_name']] = [];
|
||||||
}
|
}
|
||||||
$aOldSchema[$sTable]['INDEXES'][$aRow2['Key_name']][] = $aRow2['Column_name'];
|
$oldSchema[$table]['INDEXES'][$field['Key_name']][] = $field['Column_name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$oDataBase->iFetchType = MYSQLI_NUM; //this line is neccesary because the next fetch needs to be with MYSQLI_NUM
|
|
||||||
}
|
}
|
||||||
//finally return the array with old schema obtained from the Database
|
//finally return the array with old schema obtained from the Database
|
||||||
if (count($aOldSchema) === 0) {
|
if (count($oldSchema) === 0) {
|
||||||
$aOldSchema = null;
|
$oldSchema = null;
|
||||||
}
|
}
|
||||||
return $aOldSchema;
|
return $oldSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1154,14 +1152,14 @@ class WorkspaceTools
|
|||||||
$this->setFormatRows();
|
$this->setFormatRows();
|
||||||
|
|
||||||
$workspaceSchema = $this->getSchema($rbac);
|
$workspaceSchema = $this->getSchema($rbac);
|
||||||
$oDataBase = $this->getDatabase($rbac);
|
$database = $this->getDatabase($rbac);
|
||||||
|
|
||||||
if (!$onedb) {
|
if (!$onedb) {
|
||||||
if ($rbac) {
|
if ($rbac) {
|
||||||
$rename = System::verifyRbacSchema($workspaceSchema);
|
$rename = System::verifyRbacSchema($workspaceSchema);
|
||||||
if (count($rename) > 0) {
|
if (count($rename) > 0) {
|
||||||
foreach ($rename as $tableName) {
|
foreach ($rename as $tableName) {
|
||||||
$oDataBase->executeQuery($oDataBase->generateRenameTableSQL($tableName));
|
$database->executeQuery($database->generateRenameTableSQL($tableName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1184,19 +1182,19 @@ class WorkspaceTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$oDataBase->iFetchType = $this->num;
|
$database->iFetchType = $this->num;
|
||||||
|
|
||||||
$oDataBase->logQuery(count($changes));
|
$database->logQuery(count($changes));
|
||||||
|
|
||||||
if (!empty($changes['tablesToAdd'])) {
|
if (!empty($changes['tablesToAdd'])) {
|
||||||
CLI::logging("-> " . count($changes['tablesToAdd']) . " tables to add\n");
|
CLI::logging("-> " . count($changes['tablesToAdd']) . " tables to add\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($changes['tablesToAdd'] as $sTable => $aColumns) {
|
foreach ($changes['tablesToAdd'] as $sTable => $aColumns) {
|
||||||
$oDataBase->executeQuery($oDataBase->generateCreateTableSQL($sTable, $aColumns));
|
$database->executeQuery($database->generateCreateTableSQL($sTable, $aColumns));
|
||||||
if (isset($changes['tablesToAdd'][$sTable]['INDEXES'])) {
|
if (isset($changes['tablesToAdd'][$sTable]['INDEXES'])) {
|
||||||
foreach ($changes['tablesToAdd'][$sTable]['INDEXES'] as $indexName => $aIndex) {
|
foreach ($changes['tablesToAdd'][$sTable]['INDEXES'] as $indexName => $aIndex) {
|
||||||
$oDataBase->executeQuery($oDataBase->generateAddKeysSQL($sTable, $indexName, $aIndex));
|
$database->executeQuery($database->generateAddKeysSQL($sTable, $indexName, $aIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1210,17 +1208,17 @@ class WorkspaceTools
|
|||||||
foreach ($aAction as $sColumn => $vData) {
|
foreach ($aAction as $sColumn => $vData) {
|
||||||
switch ($sAction) {
|
switch ($sAction) {
|
||||||
case 'DROP':
|
case 'DROP':
|
||||||
$oDataBase->executeQuery($oDataBase->generateDropColumnSQL($sTable, $vData));
|
$database->executeQuery($database->generateDropColumnSQL($sTable, $vData));
|
||||||
break;
|
break;
|
||||||
case 'ADD':
|
case 'ADD':
|
||||||
if ($oDataBase->checkPatchHor1787($sTable, $sColumn, $vData)) {
|
if ($database->checkPatchHor1787($sTable, $sColumn, $vData)) {
|
||||||
$oDataBase->executeQuery($oDataBase->generateCheckAddColumnSQL($sTable, $sColumn, $vData));
|
$database->executeQuery($database->generateCheckAddColumnSQL($sTable, $sColumn, $vData));
|
||||||
$oDataBase->executeQuery($oDataBase->deleteAllIndexesIntable($sTable, $sColumn, $vData));
|
$database->executeQuery($database->deleteAllIndexesIntable($sTable, $sColumn, $vData));
|
||||||
}
|
}
|
||||||
$oDataBase->executeQuery($oDataBase->generateAddColumnSQL($sTable, $sColumn, $vData));
|
$database->executeQuery($database->generateAddColumnSQL($sTable, $sColumn, $vData));
|
||||||
break;
|
break;
|
||||||
case 'CHANGE':
|
case 'CHANGE':
|
||||||
$oDataBase->executeQuery($oDataBase->generateChangeColumnSQL($sTable, $sColumn, $vData));
|
$database->executeQuery($database->generateChangeColumnSQL($sTable, $sColumn, $vData));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1232,7 +1230,7 @@ class WorkspaceTools
|
|||||||
}
|
}
|
||||||
foreach ($changes['tablesWithNewIndex'] as $sTable => $aIndexes) {
|
foreach ($changes['tablesWithNewIndex'] as $sTable => $aIndexes) {
|
||||||
foreach ($aIndexes as $sIndexName => $aIndexFields) {
|
foreach ($aIndexes as $sIndexName => $aIndexFields) {
|
||||||
$oDataBase->executeQuery($oDataBase->generateAddKeysSQL($sTable, $sIndexName, $aIndexFields));
|
$database->executeQuery($database->generateAddKeysSQL($sTable, $sIndexName, $aIndexFields));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1241,8 +1239,8 @@ class WorkspaceTools
|
|||||||
}
|
}
|
||||||
foreach ($changes['tablesToAlterIndex'] as $sTable => $aIndexes) {
|
foreach ($changes['tablesToAlterIndex'] as $sTable => $aIndexes) {
|
||||||
foreach ($aIndexes as $sIndexName => $aIndexFields) {
|
foreach ($aIndexes as $sIndexName => $aIndexFields) {
|
||||||
$oDataBase->executeQuery($oDataBase->generateDropKeySQL($sTable, $sIndexName));
|
$database->executeQuery($database->generateDropKeySQL($sTable, $sIndexName));
|
||||||
$oDataBase->executeQuery($oDataBase->generateAddKeysSQL($sTable, $sIndexName, $aIndexFields));
|
$database->executeQuery($database->generateAddKeysSQL($sTable, $sIndexName, $aIndexFields));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->closeDatabase();
|
$this->closeDatabase();
|
||||||
@@ -1288,7 +1286,7 @@ class WorkspaceTools
|
|||||||
case 4:
|
case 4:
|
||||||
$sql = $dataBase->generateSelectSQL($data['table'], $data['keys'], $data['data']);
|
$sql = $dataBase->generateSelectSQL($data['table'], $data['keys'], $data['data']);
|
||||||
$dataset = $dataBase->executeQuery($sql);
|
$dataset = $dataBase->executeQuery($sql);
|
||||||
if ($dataBase->getRegistry($dataset)) {
|
if ($dataset) {
|
||||||
$sql = $dataBase->generateDeleteSQL($data['table'], $data['keys'], $data['data']);
|
$sql = $dataBase->generateDeleteSQL($data['table'], $data['keys'], $data['data']);
|
||||||
$dataBase->executeQuery($sql);
|
$dataBase->executeQuery($sql);
|
||||||
}
|
}
|
||||||
@@ -1414,31 +1412,31 @@ class WorkspaceTools
|
|||||||
/**
|
/**
|
||||||
* exports this workspace database to the specified path
|
* exports this workspace database to the specified path
|
||||||
*
|
*
|
||||||
* This function is used mainly for backup purposes.
|
|
||||||
*
|
|
||||||
* @param string $path the directory where to create the sql files
|
* @param string $path the directory where to create the sql files
|
||||||
|
* @param boolean $onedb
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function exportDatabase($path, $onedb = false)
|
public function exportDatabase($path, $onedb = false)
|
||||||
{
|
{
|
||||||
$dbInfo = $this->getDBInfo();
|
$dbInfo = $this->getDBInfo();
|
||||||
|
|
||||||
|
$databases = ['wf', 'rp', 'rb'];
|
||||||
if ($onedb) {
|
if ($onedb) {
|
||||||
$databases = array("rb", "rp");
|
$databases = ['rb', 'rp'];
|
||||||
} elseif ($dbInfo['DB_NAME'] == $dbInfo['DB_RBAC_NAME']) {
|
} else if ($dbInfo['DB_NAME'] === $dbInfo['DB_RBAC_NAME']) {
|
||||||
$databases = array("wf");
|
$databases = ['wf'];
|
||||||
} else {
|
|
||||||
$databases = array("wf", "rp", "rb");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbNames = [];
|
$dbNames = [];
|
||||||
|
|
||||||
foreach ($databases as $db) {
|
foreach ($databases as $db) {
|
||||||
$dbInfo = $this->getDBCredentials($db);
|
$dbInfo = $this->getDBCredentials($db);
|
||||||
$oDbMaintainer = new DataBaseMaintenance($dbInfo["host"], $dbInfo["user"], $dbInfo["pass"]);
|
$oDbMaintainer = new DataBaseMaintenance($dbInfo['host'], $dbInfo['user'], $dbInfo['pass']);
|
||||||
CLI::logging("Saving database {$dbInfo["name"]}\n");
|
CLI::logging("Saving database {$dbInfo['name']}\n");
|
||||||
$oDbMaintainer->connect($dbInfo["name"]);
|
$oDbMaintainer->connect($dbInfo['name']);
|
||||||
$oDbMaintainer->setTempDir($path . "/");
|
$oDbMaintainer->setTempDir($path . '/');
|
||||||
$oDbMaintainer->backupDataBase($oDbMaintainer->getTempDir() . $dbInfo["name"] . ".sql");
|
$oDbMaintainer->backupDataBase($oDbMaintainer->getTempDir() . $dbInfo['name'] . '.sql');
|
||||||
$dbNames[] = $dbInfo;
|
$dbNames[] = $dbInfo;
|
||||||
}
|
}
|
||||||
return $dbNames;
|
return $dbNames;
|
||||||
@@ -1548,29 +1546,29 @@ class WorkspaceTools
|
|||||||
* @param string $password password
|
* @param string $password password
|
||||||
* @param string $hostname the hostname the user will be connecting from
|
* @param string $hostname the hostname the user will be connecting from
|
||||||
* @param string $database the database to grant permissions
|
* @param string $database the database to grant permissions
|
||||||
|
* @param string $connection name
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function createDBUser($username, $password, $hostname, $database, $connection = null)
|
public function createDBUser($username, $password, $hostname, $database, $connection)
|
||||||
{
|
{
|
||||||
mysqli_select_db($connection, 'mysql');
|
try {
|
||||||
$hosts = explode(':', $hostname);
|
$message = 'Unable to retrieve users: ';
|
||||||
$hostname = array_shift($hosts);
|
$hosts = explode(':', $hostname);
|
||||||
|
$hostname = array_shift($hosts);
|
||||||
|
|
||||||
$sqlstmt = "SELECT * FROM user WHERE user = '$username' AND host = '$hostname'";
|
$result = DB::connection($connection)->select(DB::raw("SELECT * FROM mysql.user WHERE user = '$username' AND host = '$hostname'"));
|
||||||
$result = mysqli_query($connection, $sqlstmt);
|
|
||||||
if ($result === false) {
|
if (count($result) === 0) {
|
||||||
throw new Exception('Unable to retrieve users: ' . mysqli_error($connection));
|
$message = "Unable to create user $username: ";
|
||||||
}
|
CLI::logging("Creating user $username for $hostname\n");
|
||||||
$users = mysqli_num_rows($result);
|
|
||||||
if ($users === 0) {
|
DB::connection($connection)->statement("CREATE USER '$username'@'$hostname' IDENTIFIED BY '$password'");
|
||||||
CLI::logging("Creating user $username for $hostname\n");
|
|
||||||
$result = mysqli_query($connection, "CREATE USER '$username'@'$hostname' IDENTIFIED BY '$password'");
|
|
||||||
if ($result === false) {
|
|
||||||
throw new Exception("Unable to create user $username: " . mysqli_error($connection));
|
|
||||||
}
|
}
|
||||||
}
|
$message = "Unable to grant priviledges to user $username: ";
|
||||||
$result = mysqli_query($connection, "GRANT ALL ON $database.* TO '$username'@'$hostname'");
|
DB::connection($connection)->statement("GRANT ALL ON $database.* TO '$username'@'$hostname'");
|
||||||
if ($result === false) {
|
} catch (QueryException $exception) {
|
||||||
throw new Exception("Unable to grant priviledges to user $username: " . mysqli_error($connection));
|
throw new Exception($message . $exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1596,19 +1594,20 @@ class WorkspaceTools
|
|||||||
* @param string $database the database to execute this script into
|
* @param string $database the database to execute this script into
|
||||||
* @param $parameters
|
* @param $parameters
|
||||||
* @param int $versionBackupEngine
|
* @param int $versionBackupEngine
|
||||||
* @param object $connection
|
* @param string $connection
|
||||||
*/
|
*/
|
||||||
public function executeSQLScript($database, $filename, $parameters, $versionBackupEngine = 1, $connection = null)
|
public function executeSQLScript($database, $filename, $parameters, $versionBackupEngine = 1, $connection)
|
||||||
{
|
{
|
||||||
mysqli_query($connection, 'CREATE DATABASE IF NOT EXISTS ' . mysqli_real_escape_string($connection, $database));
|
DB::connection($connection)
|
||||||
|
->statement('CREATE DATABASE IF NOT EXISTS ' . $database);
|
||||||
|
|
||||||
//check function shell_exec
|
//check function shell_exec
|
||||||
$disabled_functions = ini_get('disable_functions');
|
$disabled_functions = ini_get('disable_functions');
|
||||||
$flag = false;
|
$flag = false;
|
||||||
if ($disabled_functions != '') {
|
if (!empty($disabled_functions)) {
|
||||||
$arr = explode(',', $disabled_functions);
|
$arr = explode(',', $disabled_functions);
|
||||||
sort($arr);
|
sort($arr);
|
||||||
if (in_array("shell_exec", $arr)) {
|
if (in_array('shell_exec', $arr)) {
|
||||||
$flag = true;
|
$flag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1619,8 +1618,8 @@ class WorkspaceTools
|
|||||||
$flagFunction = shell_exec('mysql --version');
|
$flagFunction = shell_exec('mysql --version');
|
||||||
}
|
}
|
||||||
|
|
||||||
$arrayRegExpEngineSearch = array("/\)\s*TYPE\s*=\s*(InnoDB)/i", "/\)\s*TYPE\s*=\s*(MyISAM)/i", "/SET\s*FOREIGN_KEY_CHECKS\s*=\s*0\s*;/");
|
$arrayRegExpEngineSearch = ["/\)\s*TYPE\s*=\s*(InnoDB)/i", "/\)\s*TYPE\s*=\s*(MyISAM)/i", "/SET\s*FOREIGN_KEY_CHECKS\s*=\s*0\s*;/"];
|
||||||
$arrayRegExpEngineReplace = array(") ENGINE=\\1 DEFAULT CHARSET=utf8", ") ENGINE=\\1", "SET FOREIGN_KEY_CHECKS=0;\nSET unique_checks=0;\nSET AUTOCOMMIT=0;");
|
$arrayRegExpEngineReplace = [") ENGINE=\\1 DEFAULT CHARSET=utf8", ") ENGINE=\\1", "SET FOREIGN_KEY_CHECKS=0;\nSET unique_checks=0;\nSET AUTOCOMMIT=0;"];
|
||||||
|
|
||||||
//replace DEFINER
|
//replace DEFINER
|
||||||
$script = preg_replace('/DEFINER=[^*]*/', '', file_get_contents($filename));
|
$script = preg_replace('/DEFINER=[^*]*/', '', file_get_contents($filename));
|
||||||
@@ -1632,8 +1631,8 @@ class WorkspaceTools
|
|||||||
$script = preg_replace($arrayRegExpEngineSearch, $arrayRegExpEngineReplace, file_get_contents($filename));
|
$script = preg_replace($arrayRegExpEngineSearch, $arrayRegExpEngineReplace, file_get_contents($filename));
|
||||||
file_put_contents($filename, $script . "\nCOMMIT;");
|
file_put_contents($filename, $script . "\nCOMMIT;");
|
||||||
} else {
|
} else {
|
||||||
$arrayRegExpEngineSearch = array("/\)\s*TYPE\s*=\s*(InnoDB)/i", "/\)\s*TYPE\s*=\s*(MyISAM)/i");
|
$arrayRegExpEngineSearch = ["/\)\s*TYPE\s*=\s*(InnoDB)/i", "/\)\s*TYPE\s*=\s*(MyISAM)/i"];
|
||||||
$arrayRegExpEngineReplace = array(") ENGINE=\\1 DEFAULT CHARSET=utf8", ") ENGINE=\\1");
|
$arrayRegExpEngineReplace = [") ENGINE=\\1 DEFAULT CHARSET=utf8", ") ENGINE=\\1"];
|
||||||
$script = preg_replace($arrayRegExpEngineSearch, $arrayRegExpEngineReplace, file_get_contents($filename));
|
$script = preg_replace($arrayRegExpEngineSearch, $arrayRegExpEngineReplace, file_get_contents($filename));
|
||||||
file_put_contents($filename, $script);
|
file_put_contents($filename, $script);
|
||||||
}
|
}
|
||||||
@@ -1647,7 +1646,7 @@ class WorkspaceTools
|
|||||||
. ' --port=' . $dbPort
|
. ' --port=' . $dbPort
|
||||||
. ' --user=' . $parameters['dbUser']
|
. ' --user=' . $parameters['dbUser']
|
||||||
. ' --password=' . escapeshellarg($parameters['dbPass'])
|
. ' --password=' . escapeshellarg($parameters['dbPass'])
|
||||||
. ' --database=' . mysqli_real_escape_string($connection, $database)
|
. ' --database=' . $database
|
||||||
. ' --default_character_set utf8'
|
. ' --default_character_set utf8'
|
||||||
. ' --execute="SOURCE ' . $filename . '"';
|
. ' --execute="SOURCE ' . $filename . '"';
|
||||||
} else {
|
} else {
|
||||||
@@ -1655,7 +1654,7 @@ class WorkspaceTools
|
|||||||
. ' --host=' . $dbHost
|
. ' --host=' . $dbHost
|
||||||
. ' --user=' . $parameters['dbUser']
|
. ' --user=' . $parameters['dbUser']
|
||||||
. ' --password=' . escapeshellarg($parameters['dbPass'])
|
. ' --password=' . escapeshellarg($parameters['dbPass'])
|
||||||
. ' --database=' . mysqli_real_escape_string($connection, $database)
|
. ' --database=' . $database
|
||||||
. ' --default_character_set utf8'
|
. ' --default_character_set utf8'
|
||||||
. ' --execute="SOURCE ' . $filename . '"';
|
. ' --execute="SOURCE ' . $filename . '"';
|
||||||
}
|
}
|
||||||
@@ -1663,7 +1662,8 @@ class WorkspaceTools
|
|||||||
} else {
|
} else {
|
||||||
//If the safe mode of the server is actived
|
//If the safe mode of the server is actived
|
||||||
try {
|
try {
|
||||||
mysqli_select_db($connection, $database);
|
$connection = 'RESTORE_' . $database;
|
||||||
|
InstallerModule::setNewConnection($connection, $parameters['dbHost'], $parameters['dbUser'], $parameters['dbPass'], $database, '');
|
||||||
|
|
||||||
//Replace TYPE by ENGINE
|
//Replace TYPE by ENGINE
|
||||||
$script = preg_replace($arrayRegExpEngineSearch, $arrayRegExpEngineReplace, file_get_contents($filename));
|
$script = preg_replace($arrayRegExpEngineSearch, $arrayRegExpEngineReplace, file_get_contents($filename));
|
||||||
@@ -1677,51 +1677,55 @@ class WorkspaceTools
|
|||||||
foreach ($lines as $j => $line) {
|
foreach ($lines as $j => $line) {
|
||||||
// Remove comments from the script
|
// Remove comments from the script
|
||||||
$line = trim($line);
|
$line = trim($line);
|
||||||
if (strpos($line, "--") === 0) {
|
if (strpos($line, '--') === 0) {
|
||||||
$line = substr($line, 0, strpos($line, "--"));
|
$line = substr($line, 0, strpos($line, '--'));
|
||||||
}
|
}
|
||||||
if (empty($line)) {
|
if (empty($line)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Concatenate the previous line, if any, with the current
|
// Concatenate the previous line, if any, with the current
|
||||||
if ($previous) {
|
if ($previous) {
|
||||||
$line = $previous . " " . $line;
|
$line = $previous . ' ' . $line;
|
||||||
}
|
}
|
||||||
$previous = null;
|
$previous = null;
|
||||||
|
|
||||||
// If the current line doesnt end with ; then put this line together
|
// If the current line doesnt end with ; then put this line together
|
||||||
// with the next one, thus supporting multi-line statements.
|
// with the next one, thus supporting multi-line statements.
|
||||||
if (strrpos($line, ";") != strlen($line) - 1) {
|
if (strrpos($line, ';') !== strlen($line) - 1) {
|
||||||
$previous = $line;
|
$previous = $line;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$line = substr($line, 0, strrpos($line, ";"));
|
$line = substr($line, 0, strrpos($line, ';'));
|
||||||
|
|
||||||
if (strrpos($line, "INSERT INTO") !== false) {
|
if (strrpos($line, 'INSERT INTO') !== false) {
|
||||||
$insert = true;
|
$insert = true;
|
||||||
if ($insert) {
|
if ($insert) {
|
||||||
$result = mysqli_query($connection, "START TRANSACTION");
|
DB::connection($connection)->beginTransaction();
|
||||||
$insert = false;
|
$insert = false;
|
||||||
}
|
}
|
||||||
$result = mysqli_query($connection, $line);
|
$result = DB::connection($connection)->statement($line);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (!$insert) {
|
if (!$insert) {
|
||||||
$result = mysqli_query($connection, "COMMIT");
|
DB::connection($connection)->commitTransaction();
|
||||||
$insert = true;
|
$insert = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = mysqli_query($connection, $line);
|
$result = DB::connection($connection)->statement($line);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new Exception("Error when running script '$filename', line $j, query '$line': " . mysqli_error($connection));
|
DB::connection($connection)->rollbackTransaction();
|
||||||
|
throw new Exception("Error when running script '$filename', line $j, query '$line' ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$insert) {
|
if (!$insert) {
|
||||||
$result = mysqli_query($connection, "COMMIT");
|
DB::connection($connection)->commitTransaction();
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
CLI::logging(CLI::error("Error:" . "There are problems running script '$filename': " . $e));
|
CLI::logging(CLI::error("Error:" . "There are problems running script '$filename': " . $e));
|
||||||
|
} catch (QueryException $exception) {
|
||||||
|
DB::connection($connection)->rollbackTransaction();
|
||||||
|
throw new Exception("Error when running script '$filename', line $j, query '$line': " . $exception->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1919,28 +1923,31 @@ class WorkspaceTools
|
|||||||
if ($port != '') {
|
if ($port != '') {
|
||||||
$dbHost = $dbHost . $port; //127.0.0.1:3306
|
$dbHost = $dbHost . $port; //127.0.0.1:3306
|
||||||
}
|
}
|
||||||
$aParameters = array('dbHost' => $dbHost, 'dbUser' => $dbUser, 'dbPass' => $dbPass);
|
$aParameters = ['dbHost' => $dbHost, 'dbUser' => $dbUser, 'dbPass' => $dbPass];
|
||||||
|
|
||||||
//Restore
|
//Restore
|
||||||
if (empty(config("system.workspace"))) {
|
if (empty(config('system.workspace'))) {
|
||||||
define("SYS_SYS", $workspaceName);
|
define('SYS_SYS', $workspaceName);
|
||||||
config(["system.workspace" => $workspaceName]);
|
config(['system.workspace' => $workspaceName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined("PATH_DATA_SITE")) {
|
if (!defined('PATH_DATA_SITE')) {
|
||||||
define("PATH_DATA_SITE", PATH_DATA . "sites" . PATH_SEP . config("system.workspace") . PATH_SEP);
|
define('PATH_DATA_SITE', PATH_DATA . 'sites' . PATH_SEP . config('system.workspace') . PATH_SEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pmVersionWorkspaceToRestore = (preg_match("/^([\d\.]+).*$/", $metadata->PM_VERSION, $arrayMatch)) ? $arrayMatch[1] : "";
|
$pmVersionWorkspaceToRestore = preg_match("/^([\d\.]+).*$/", $metadata->PM_VERSION, $arrayMatch) ? $arrayMatch[1] : '';
|
||||||
|
|
||||||
CLI::logging("> Connecting to system database in '$dbHost'\n");
|
CLI::logging("> Connecting to system database in '$dbHost'\n");
|
||||||
$link = mysqli_connect($dbHost, $dbUser, $dbPass);
|
|
||||||
mysqli_query($link, "SET NAMES 'utf8';");
|
|
||||||
mysqli_query($link, "SET FOREIGN_KEY_CHECKS=0;");
|
|
||||||
mysqli_query($link, "SET GLOBAL log_bin_trust_routine_creators = 1;");
|
|
||||||
|
|
||||||
if (!$link) {
|
try {
|
||||||
throw new Exception('Could not connect to system database: ' . mysqli_error($link));
|
$connection = 'RESTORE';
|
||||||
|
InstallerModule::setNewConnection('RESTORE', $dbHost, $dbUser, $dbPass, '', '');
|
||||||
|
DB::connection($connection)
|
||||||
|
->statement("SET NAMES 'utf8'");
|
||||||
|
DB::connection($connection)
|
||||||
|
->statement('SET FOREIGN_KEY_CHECKS=0');
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
throw new Exception('Could not connect to system database: ' . $exception->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbName = '';
|
$dbName = '';
|
||||||
@@ -1952,17 +1959,16 @@ class WorkspaceTools
|
|||||||
if (isset($newDBNames['DB_USER'])) {
|
if (isset($newDBNames['DB_USER'])) {
|
||||||
$dbUser = $newDBNames['DB_USER'];
|
$dbUser = $newDBNames['DB_USER'];
|
||||||
}
|
}
|
||||||
if (mysqli_select_db($link, $dbName)) {
|
$result = DB::connection($connection)->select("show databases like '$dbName'");
|
||||||
if (!$overwrite) {
|
if (count($result) > 0 && !$overwrite) {
|
||||||
throw new Exception("Destination Database already exist (use -o to overwrite)");
|
throw new Exception("Destination Database already exist (use -o to overwrite)");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CLI::logging("+> Restoring database {$db->name} to $dbName\n");
|
CLI::logging("+> Restoring database {$db->name} to $dbName\n");
|
||||||
$versionBackupEngine = (isset($metadata->backupEngineVersion)) ? $metadata->backupEngineVersion : 1;
|
$versionBackupEngine = (isset($metadata->backupEngineVersion)) ? $metadata->backupEngineVersion : 1;
|
||||||
$workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql", $aParameters, $versionBackupEngine, $link);
|
$workspace->executeSQLScript($dbName, "$tempDirectory/{$db->name}.sql", $aParameters, $versionBackupEngine, $connection);
|
||||||
$workspace->createDBUser($dbUser, ($workspace->dbGrantUserPassword != '' ? $workspace->dbGrantUserPassword : $db->pass), "localhost", $dbName, $link);
|
$workspace->createDBUser($dbUser, ($workspace->dbGrantUserPassword != '' ? $workspace->dbGrantUserPassword : $db->pass), "localhost", $dbName, $connection);
|
||||||
$workspace->createDBUser($dbUser, ($workspace->dbGrantUserPassword != '' ? $workspace->dbGrantUserPassword : $db->pass), "%", $dbName, $link);
|
$workspace->createDBUser($dbUser, ($workspace->dbGrantUserPassword != '' ? $workspace->dbGrantUserPassword : $db->pass), "%", $dbName, $connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2048,7 +2054,6 @@ class WorkspaceTools
|
|||||||
//Updating generated class files for PM Tables
|
//Updating generated class files for PM Tables
|
||||||
passthru(PHP_BINARY . ' processmaker regenerate-pmtable-classes ' . $workspace->name);
|
passthru(PHP_BINARY . ' processmaker regenerate-pmtable-classes ' . $workspace->name);
|
||||||
|
|
||||||
mysqli_close($link);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CLI::logging("Removing temporary files\n");
|
CLI::logging("Removing temporary files\n");
|
||||||
|
|||||||
@@ -1,43 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Content.php
|
|
||||||
*
|
|
||||||
* @package workflow.engine.classes.model
|
|
||||||
*
|
|
||||||
* ProcessMaker Open Source Edition
|
|
||||||
* Copyright (C) 2004 - 2011 Colosa Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
||||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
//require_once 'classes/model/om/BaseContent.php';
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
/**
|
|
||||||
* Skeleton subclass for representing a row from the 'CONTENT' table.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* You should add additional methods to this class to meet the
|
|
||||||
* application requirements. This class will only be generated as
|
|
||||||
* long as it does not already exist in the output directory.
|
|
||||||
*
|
|
||||||
* @package workflow.engine.classes.model
|
|
||||||
*/
|
|
||||||
class Content extends BaseContent
|
class Content extends BaseContent
|
||||||
{
|
{
|
||||||
public $langs;
|
public $langs;
|
||||||
@@ -335,51 +299,56 @@ class Content extends BaseContent
|
|||||||
$this->rowsUnchanged = 0;
|
$this->rowsUnchanged = 0;
|
||||||
$this->rowsClustered = 0;
|
$this->rowsClustered = 0;
|
||||||
|
|
||||||
//Creating table CONTENT_BACKUP
|
$workSpace = new WorkspaceTools($workSpace);
|
||||||
$connection = Propel::getConnection('workflow');
|
$workSpace->getDBInfo();
|
||||||
$oStatement = $connection->prepareStatement("CREATE TABLE IF NOT EXISTS `CONTENT_BACKUP` (
|
|
||||||
|
$connection = 'regenerate';
|
||||||
|
InstallerModule::setNewConnection(
|
||||||
|
$connection,
|
||||||
|
$workSpace->dbHost,
|
||||||
|
$workSpace->dbUser,
|
||||||
|
$workSpace->dbPass,
|
||||||
|
$workSpace->dbName,
|
||||||
|
'',
|
||||||
|
['PDO::MYSQL_ATTR_INIT_COMMAND' => 'SET SESSION SQL_BIG_SELECTS=1']);
|
||||||
|
|
||||||
|
$query = "CREATE TABLE IF NOT EXISTS `CONTENT_BACKUP` (
|
||||||
`CON_CATEGORY` VARCHAR(30) default '' NOT NULL,
|
`CON_CATEGORY` VARCHAR(30) default '' NOT NULL,
|
||||||
`CON_PARENT` VARCHAR(32) default '' NOT NULL,
|
`CON_PARENT` VARCHAR(32) default '' NOT NULL,
|
||||||
`CON_ID` VARCHAR(100) default '' NOT NULL,
|
`CON_ID` VARCHAR(100) default '' NOT NULL,
|
||||||
`CON_LANG` VARCHAR(10) default '' NOT NULL,
|
`CON_LANG` VARCHAR(10) default '' NOT NULL,
|
||||||
`CON_VALUE` MEDIUMTEXT NOT NULL,
|
`CON_VALUE` MEDIUMTEXT NOT NULL,
|
||||||
CONSTRAINT CONTENT_BACKUP_PK PRIMARY KEY (CON_CATEGORY,CON_PARENT,CON_ID,CON_LANG)
|
CONSTRAINT CONTENT_BACKUP_PK PRIMARY KEY (CON_CATEGORY,CON_PARENT,CON_ID,CON_LANG)
|
||||||
)Engine=InnoDB DEFAULT CHARSET='utf8' COMMENT='Table for add content';");
|
)Engine=InnoDB DEFAULT CHARSET='utf8' COMMENT='Table for add content'";
|
||||||
$oStatement->executeQuery();
|
|
||||||
|
|
||||||
$sql = ' SELECT DISTINCT CON_LANG FROM CONTENT ';
|
DB::connection($connection)->statement($query);
|
||||||
$stmt = $connection->createStatement();
|
|
||||||
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
$languages = DB::table('CONTENT')->select('CON_LANG')->distinct()->get();
|
||||||
while ($rs->next()) {
|
|
||||||
$row = $rs->getRow();
|
foreach ($languages as $value) {
|
||||||
$language = $row['CON_LANG'];
|
if (array_search($value->CON_LANG, $langs) === false) {
|
||||||
if (array_search($row['CON_LANG'], $langs) === false) {
|
Content::removeLanguageContent($value->CON_LANG);
|
||||||
Content::removeLanguageContent($row['CON_LANG']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = " SELECT CON_ID, CON_CATEGORY, CON_LANG, CON_PARENT, CON_VALUE
|
DB::connection($connection)->statement('SET NAMES "utf8"');
|
||||||
FROM CONTENT
|
DB::connection($connection)->statement('SET FOREIGN_KEY_CHECKS=0');
|
||||||
ORDER BY CON_ID, CON_CATEGORY, CON_PARENT, CON_LANG";
|
DB::connection($connection)->statement('SET SQL_BIG_SELECTS=1');
|
||||||
|
|
||||||
$workSpace = new WorkspaceTools($workSpace);
|
$result = DB::table('CONTENT')
|
||||||
$workSpace->getDBInfo();
|
->select('CON_ID', 'CON_CATEGORY', 'CON_LANG', 'CON_PARENT', 'CON_VALUE')
|
||||||
|
->orderBy('CON_ID', 'CON_CATEGORY', 'CON_LANG', 'CON_PARENT', 'CON_VALUE')
|
||||||
$mysqli = new mysqli($workSpace->dbHost, $workSpace->dbUser, $workSpace->dbPass, $workSpace->dbName) or die("Could not connect");
|
->get();
|
||||||
|
|
||||||
$mysqli->query( 'SET NAMES "utf8";');
|
|
||||||
$mysqli->query( 'SET FOREIGN_KEY_CHECKS=0;');
|
|
||||||
$mysqli->query( 'SET OPTION SQL_BIG_SELECTS=1');
|
|
||||||
$result = $mysqli->query( $sql, MYSQLI_USE_RESULT);
|
|
||||||
$list = [];
|
$list = [];
|
||||||
$default = [];
|
$default = [];
|
||||||
$sw = array('CON_ID' => '','CON_CATEGORY' => '','CON_PARENT' => ''
|
$sw = ['CON_ID' => '', 'CON_CATEGORY' => '', 'CON_PARENT' => ''];
|
||||||
);
|
|
||||||
while ($row = $result->fetch_assoc()) {
|
foreach ($result as $value) {
|
||||||
|
$row = (array)$value;
|
||||||
if ($sw['CON_ID'] === $row['CON_ID'] && $sw['CON_CATEGORY'] === $row['CON_CATEGORY'] && $sw['CON_PARENT'] === $row['CON_PARENT']) {
|
if ($sw['CON_ID'] === $row['CON_ID'] && $sw['CON_CATEGORY'] === $row['CON_CATEGORY'] && $sw['CON_PARENT'] === $row['CON_PARENT']) {
|
||||||
$list[] = $row;
|
$list[] = $row;
|
||||||
} else {
|
} else {
|
||||||
$this->rowsClustered ++;
|
$this->rowsClustered++;
|
||||||
if (count($langs) !== count($list)) {
|
if (count($langs) !== count($list)) {
|
||||||
$this->checkLanguage($list, $default);
|
$this->checkLanguage($list, $default);
|
||||||
} else {
|
} else {
|
||||||
@@ -399,37 +368,30 @@ class Content extends BaseContent
|
|||||||
if ($sw['CON_LANG'] === $langs[$key]) {
|
if ($sw['CON_LANG'] === $langs[$key]) {
|
||||||
$default = $row;
|
$default = $row;
|
||||||
}
|
}
|
||||||
$this->rowsProcessed ++;
|
$this->rowsProcessed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($langs) !== count($list)) {
|
if (count($langs) !== count($list)) {
|
||||||
$this->checkLanguage($list, $default);
|
$this->checkLanguage($list, $default);
|
||||||
} else {
|
} else {
|
||||||
$this->rowsUnchanged += count($langs);
|
$this->rowsUnchanged += count($langs);
|
||||||
}
|
}
|
||||||
mysqli_free_result($result);
|
|
||||||
$total = $this->rowsProcessed + $this->rowsInserted;
|
$total = $this->rowsProcessed + $this->rowsInserted;
|
||||||
|
|
||||||
$result->close();
|
DB::connection($connection)->statement('REPLACE INTO CONTENT
|
||||||
|
|
||||||
$statement = $connection->prepareStatement("REPLACE INTO CONTENT
|
|
||||||
SELECT CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE
|
SELECT CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE
|
||||||
FROM CONTENT_BACKUP");
|
FROM CONTENT_BACKUP');
|
||||||
$statement->executeQuery();
|
|
||||||
|
|
||||||
$statement = $connection->prepareStatement("DROP TABLE CONTENT_BACKUP");
|
DB::connection($connection)->statement('DROP TABLE CONTENT_BACKUP');
|
||||||
$statement->executeQuery();
|
|
||||||
|
|
||||||
//close connection
|
$result = DB::connection($connection)
|
||||||
$sql = "SELECT * FROM information_schema.processlist WHERE command = 'Sleep' and user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() ORDER BY id;";
|
->select("SELECT * FROM information_schema.processlist WHERE command = 'Sleep' and user = SUBSTRING_INDEX(USER(),'@',1) and db = DATABASE() ORDER BY id");
|
||||||
$stmt = $connection->createStatement();
|
|
||||||
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
foreach ($result as $value) {
|
||||||
while ($rs->next()) {
|
DB::connection($connection)->statement('kill ' . $value->ID);
|
||||||
$row = $rs->getRow();
|
|
||||||
$oStatement = $connection->prepareStatement("kill ". $row['ID']);
|
|
||||||
$oStatement->executeQuery();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($_SERVER['SERVER_NAME'])) {
|
if (!isset($_SERVER['SERVER_NAME'])) {
|
||||||
CLI::logging("Rows Processed ---> $this->rowsProcessed ..... \n");
|
CLI::logging("Rows Processed ---> $this->rowsProcessed ..... \n");
|
||||||
CLI::logging("Rows Clustered ---> $this->rowsClustered ..... \n");
|
CLI::logging("Rows Clustered ---> $this->rowsClustered ..... \n");
|
||||||
CLI::logging("Rows Unchanged ---> $this->rowsUnchanged ..... \n");
|
CLI::logging("Rows Unchanged ---> $this->rowsUnchanged ..... \n");
|
||||||
@@ -457,12 +419,14 @@ class Content extends BaseContent
|
|||||||
|
|
||||||
public function fastInsertContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
|
public function fastInsertContent($ConCategory, $ConParent, $ConId, $ConLang, $ConValue)
|
||||||
{
|
{
|
||||||
$connection = Propel::getConnection('workflow');
|
DB::table('CONTENT_BACKUP')
|
||||||
$ConValue = mysqli_real_escape_string($connection, $ConValue);
|
->insert([
|
||||||
$statement = $connection->prepareStatement("INSERT INTO CONTENT_BACKUP (
|
'CON_CATEGORY' => $ConCategory,
|
||||||
CON_CATEGORY, CON_PARENT, CON_ID , CON_LANG, CON_VALUE)
|
'CON_PARENT' => $ConParent,
|
||||||
VALUES ('$ConCategory', '$ConParent', '$ConId', '$ConLang', '$ConValue');");
|
'CON_ID' => $ConId,
|
||||||
$statement->executeQuery();
|
'CON_LANG' => $ConLang,
|
||||||
|
'CON_VALUE' => $ConValue
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeLanguageContent($lanId)
|
public function removeLanguageContent($lanId)
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use ProcessMaker\Util\Common;
|
||||||
use ProcessMaker\Core\System;
|
use ProcessMaker\Core\System;
|
||||||
|
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
global $translation;
|
global $translation;
|
||||||
|
|
||||||
include PATH_LANGUAGECONT . "translation." . SYS_LANG;
|
include PATH_LANGUAGECONT . "translation." . SYS_LANG;
|
||||||
@@ -18,7 +23,18 @@ class InstallerModule extends Controller
|
|||||||
|
|
||||||
public $link; #resource for database connection
|
public $link; #resource for database connection
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default name for connection
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const CONNECTION_INSTALL = 'install';
|
||||||
|
const CONNECTION_TEST_INSTALL = 'testInstall';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* We defined the paths for the installer
|
||||||
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->path_config = PATH_CORE . 'config/';
|
$this->path_config = PATH_CORE . 'config/';
|
||||||
@@ -116,6 +132,56 @@ class InstallerModule extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set config connection
|
||||||
|
*
|
||||||
|
* @param string $nameConnection name Connection
|
||||||
|
* @param string $host
|
||||||
|
* @param string $user
|
||||||
|
* @param string $pass
|
||||||
|
* @param string $database
|
||||||
|
* @param int $port
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static function setNewConnection($nameConnection, $host, $user, $pass, $database, $port, $options = [])
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (empty($port)) {
|
||||||
|
$dbHost = explode(':', $host);
|
||||||
|
$port = 3306;
|
||||||
|
if (count($dbHost) > 1) {
|
||||||
|
$port = $dbHost[1];
|
||||||
|
}
|
||||||
|
$host = $dbHost[0];
|
||||||
|
}
|
||||||
|
config(['database.connections.' . $nameConnection => [
|
||||||
|
'driver' => 'mysql',
|
||||||
|
'host' => $host,
|
||||||
|
'port' => $port,
|
||||||
|
'database' => $database,
|
||||||
|
'username' => $user,
|
||||||
|
'password' => $pass,
|
||||||
|
'unix_socket' => '',
|
||||||
|
'charset' => 'utf8',
|
||||||
|
'collation' => 'utf8_unicode_ci',
|
||||||
|
'prefix' => '',
|
||||||
|
'strict' => false,
|
||||||
|
'engine' => 'InnoDB',
|
||||||
|
'options' => $options
|
||||||
|
]]);
|
||||||
|
DB::connection($nameConnection)->getPdo();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new Exception(G::LoadTranslation('ID_MYSQL_CREDENTIALS_WRONG'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get system information for review the requirements to install ProcessMaker
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
public function getSystemInfo()
|
public function getSystemInfo()
|
||||||
{
|
{
|
||||||
$this->setResponseType('json');
|
$this->setResponseType('json');
|
||||||
@@ -241,7 +307,7 @@ class InstallerModule extends Controller
|
|||||||
$this->setResponseType('json');
|
$this->setResponseType('json');
|
||||||
$info = new StdClass();
|
$info = new StdClass();
|
||||||
$info->success = true;
|
$info->success = true;
|
||||||
$noWritableFiles = array();
|
$noWritableFiles = [];
|
||||||
$noWritable = G::LoadTranslation('ID_INDEX_NOT_WRITEABLE');
|
$noWritable = G::LoadTranslation('ID_INDEX_NOT_WRITEABLE');
|
||||||
$writable = G::LoadTranslation('ID_WRITEABLE');
|
$writable = G::LoadTranslation('ID_WRITEABLE');
|
||||||
|
|
||||||
@@ -387,16 +453,15 @@ class InstallerModule extends Controller
|
|||||||
* the install.log files should be placed in shared/logs
|
* the install.log files should be placed in shared/logs
|
||||||
* for that reason we are using the $_REQUEST of pathShared
|
* for that reason we are using the $_REQUEST of pathShared
|
||||||
*/
|
*/
|
||||||
public function installLog($text)
|
private function installLog($text)
|
||||||
{
|
{
|
||||||
$serverAddr = $_SERVER['SERVER_ADDR'];
|
|
||||||
//if this function is called outside the createWorkspace, just returns and do nothing
|
//if this function is called outside the createWorkspace, just returns and do nothing
|
||||||
if (!isset($_REQUEST['pathShared'])) {
|
if (!isset($_REQUEST['pathShared'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//log file is in shared/logs
|
//log file is in shared/logs
|
||||||
$pathShared = trim($_REQUEST['pathShared']);
|
$pathShared = trim($_REQUEST['pathShared']);
|
||||||
if (substr($pathShared, -1) != '/') {
|
if (substr($pathShared, -1) !== '/') {
|
||||||
$pathShared .= '/';
|
$pathShared .= '/';
|
||||||
}
|
}
|
||||||
$pathSharedLog = $pathShared . 'log/';
|
$pathSharedLog = $pathShared . 'log/';
|
||||||
@@ -410,12 +475,11 @@ class InstallerModule extends Controller
|
|||||||
fwrite($fpt, sprintf("%s %s\n", date('Y:m:d H:i:s'), '----- ' . G::LoadTranslation('ID_STARTING_LOG_FILE') . ' ------'));
|
fwrite($fpt, sprintf("%s %s\n", date('Y:m:d H:i:s'), '----- ' . G::LoadTranslation('ID_STARTING_LOG_FILE') . ' ------'));
|
||||||
fclose($fpt);
|
fclose($fpt);
|
||||||
} else {
|
} else {
|
||||||
throw (new Exception(G::LoadTranslation('ID_FILE_NOT_WRITEABLE', SYS_LANG, array($logFile))));
|
throw new Exception(G::LoadTranslation('ID_FILE_NOT_WRITEABLE', SYS_LANG, [$logFile]));
|
||||||
return $false;
|
return $false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$filter = new InputFilter();
|
$filter = new InputFilter();
|
||||||
$logFile = $filter->validateInput($logFile, 'path');
|
$logFile = $filter->validateInput($logFile, 'path');
|
||||||
|
|
||||||
@@ -497,26 +561,12 @@ class InstallerModule extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* send a query to MySQL and log the query
|
* Send a query to MSSQL and log the query
|
||||||
*/
|
*
|
||||||
public function mysqlQuery($sql)
|
* @param string $sql
|
||||||
{
|
*
|
||||||
$this->installLog($sql);
|
* @return boolean
|
||||||
$query = mysqli_query($this->link, $sql);
|
* @throws Exception
|
||||||
if (!$query) {
|
|
||||||
$errorMessage = mysqli_error($this->link);
|
|
||||||
$this->installLog(G::LoadTranslation('ID_MYSQL_ERROR', SYS_LANG, array($errorMessage)));
|
|
||||||
throw new \Exception($errorMessage);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (is_object($query)) {
|
|
||||||
mysqli_free_result($query);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* send a query to MSSQL and log the query
|
|
||||||
*/
|
*/
|
||||||
public function mssqlQuery($sql)
|
public function mssqlQuery($sql)
|
||||||
{
|
{
|
||||||
@@ -544,32 +594,30 @@ class InstallerModule extends Controller
|
|||||||
public function mysqlFileQuery($file)
|
public function mysqlFileQuery($file)
|
||||||
{
|
{
|
||||||
if (!is_file($file)) {
|
if (!is_file($file)) {
|
||||||
throw (new Exception(G::LoadTranslation('ID_SQL_FILE_INVALID', SYS_LANG, array($file))));
|
throw new Exception(G::LoadTranslation('ID_SQL_FILE_INVALID', SYS_LANG, [$file]));
|
||||||
return $false;
|
return $false;
|
||||||
}
|
}
|
||||||
$this->installLog(G::LoadTranslation('ID_PROCESING', SYS_LANG, array($file)));
|
$this->installLog(G::LoadTranslation('ID_PROCESING', SYS_LANG, [$file]));
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
//New Update, to support more complex queries
|
//New Update, to support more complex queries
|
||||||
|
|
||||||
|
|
||||||
$lines = file($file);
|
$lines = file($file);
|
||||||
$previous = null;
|
$previous = null;
|
||||||
$errors = '';
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
mysqli_query($this->link, "SET NAMES 'utf8';");
|
->statement("SET NAMES 'utf8'");
|
||||||
foreach ($lines as $j => $line) {
|
foreach ($lines as $j => $line) {
|
||||||
$line = trim($line); // Remove comments from the script
|
$line = trim($line); // Remove comments from the script
|
||||||
|
|
||||||
|
if (strpos($line, '--') === 0) {
|
||||||
if (strpos($line, "--") === 0) {
|
$line = substr($line, 0, strpos($line, '--'));
|
||||||
$line = substr($line, 0, strpos($line, "--"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($line)) {
|
if (empty($line)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($line, "#") === 0) {
|
if (strpos($line, '#') === 0) {
|
||||||
$line = substr($line, 0, strpos($line, "#"));
|
$line = substr($line, 0, strpos($line, '#'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($line)) {
|
if (empty($line)) {
|
||||||
@@ -578,23 +626,24 @@ class InstallerModule extends Controller
|
|||||||
|
|
||||||
// Concatenate the previous line, if any, with the current
|
// Concatenate the previous line, if any, with the current
|
||||||
if ($previous) {
|
if ($previous) {
|
||||||
$line = $previous . " " . $line;
|
$line = $previous . ' ' . $line;
|
||||||
}
|
}
|
||||||
$previous = null;
|
$previous = null;
|
||||||
|
|
||||||
// If the current line doesnt end with ; then put this line together
|
// If the current line doesnt end with ; then put this line together
|
||||||
// with the next one, thus supporting multi-line statements.
|
// with the next one, thus supporting multi-line statements.
|
||||||
if (strrpos($line, ";") != strlen($line) - 1) {
|
if (strrpos($line, ';') !== strlen($line) - 1) {
|
||||||
$previous = $line;
|
$previous = $line;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$line = substr($line, 0, strrpos($line, ";"));
|
$line = substr($line, 0, strrpos($line, ';'));
|
||||||
mysqli_query($this->link, $line);
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
|
->statement($line);
|
||||||
}
|
}
|
||||||
|
|
||||||
$endTime = microtime(true);
|
$endTime = microtime(true);
|
||||||
$this->installLog(G::LoadTranslation('ID_FILE_PROCESSED', SYS_LANG, array(basename($file), $endTime - $startTime)));
|
$this->installLog(G::LoadTranslation('ID_FILE_PROCESSED', SYS_LANG, [basename($file), $endTime - $startTime]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -636,31 +685,25 @@ class InstallerModule extends Controller
|
|||||||
* @param string $psUser
|
* @param string $psUser
|
||||||
* @param string $psPassword
|
* @param string $psPassword
|
||||||
* @param string $psDatabase
|
* @param string $psDatabase
|
||||||
* @return void
|
* @param string $host
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function setGrantPrivilegesMySQL($psUser, $psPassword, $psDatabase, $host)
|
private function setGrantPrivilegesMySQL($psUser, $psPassword, $psDatabase, $host)
|
||||||
{
|
{
|
||||||
$filter = new InputFilter();
|
try {
|
||||||
$host = ($host == 'localhost' || $host == '127.0.0.1' ? 'localhost' : '%');
|
$host = $host === 'localhost' || $host === '127.0.0.1' ? 'localhost' : '%';
|
||||||
|
|
||||||
$query = "GRANT ALL PRIVILEGES ON `%s`.* TO %s@'%s' IDENTIFIED BY '%s' WITH GRANT OPTION";
|
$query = "GRANT ALL PRIVILEGES ON `$psDatabase`.* TO $psUser@'$host' IDENTIFIED BY '$psPassword' WITH GRANT OPTION";
|
||||||
$sql = sprintf($query, $psDatabase, $psUser, $host, $psPassword);
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
$sql = $filter->preventSqlInjection($query, array($psDatabase, $psUser, $host, $psPassword), $this->link);
|
->statement($query);
|
||||||
$query = mysqli_query($this->link, $sql);
|
|
||||||
|
|
||||||
if (!$query) {
|
$this->installLog($query);
|
||||||
$errorMessage = mysqli_error($this->link);
|
|
||||||
$this->installLog(G::LoadTranslation('ID_MYSQL_ERROR', SYS_LANG, array($errorMessage)));
|
} catch (QueryException $e) {
|
||||||
if (mysqli_errno($this->link) === 1410 || mysqli_errno($this->link) === 1132) {
|
$this->installLog(G::LoadTranslation('ID_MYSQL_ERROR', SYS_LANG, [$e->getMessage()]));
|
||||||
$errorMessage .= '. ' . G::LoadTranslation('ID_INSTALL_USE_CURRENT_USER');
|
throw new Exception($e->getMessage());
|
||||||
}
|
|
||||||
throw new Exception($errorMessage);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (is_object($query)) {
|
|
||||||
mysqli_free_result($query);
|
|
||||||
}
|
|
||||||
$this->installLog($sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -703,12 +746,11 @@ class InstallerModule extends Controller
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function file_get_contents_utf8($fn) {
|
/**
|
||||||
$content = file_get_contents($fn);
|
* Create a workspace in a MySQL database
|
||||||
return mb_convert_encoding($content, 'UTF-8',
|
*
|
||||||
mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
|
* @return StdClass object
|
||||||
}
|
*/
|
||||||
|
|
||||||
public function createMySQLWorkspace()
|
public function createMySQLWorkspace()
|
||||||
{
|
{
|
||||||
$filter = new InputFilter();
|
$filter = new InputFilter();
|
||||||
@@ -726,76 +768,61 @@ class InstallerModule extends Controller
|
|||||||
$db_password = urlencode(trim($_REQUEST['db_password']));
|
$db_password = urlencode(trim($_REQUEST['db_password']));
|
||||||
$db_password = urldecode($filter->validateInput($db_password));
|
$db_password = urldecode($filter->validateInput($db_password));
|
||||||
$wf = trim($_REQUEST['wfDatabase']);
|
$wf = trim($_REQUEST['wfDatabase']);
|
||||||
$rb = trim($_REQUEST['wfDatabase']);
|
|
||||||
$rp = trim($_REQUEST['wfDatabase']);
|
|
||||||
$workspace = trim($_REQUEST['workspace']);
|
$workspace = trim($_REQUEST['workspace']);
|
||||||
$pathConfig = trim($_REQUEST['pathConfig']);
|
|
||||||
$pathLanguages = trim($_REQUEST['pathLanguages']);
|
|
||||||
$pathPlugins = trim($_REQUEST['pathPlugins']);
|
|
||||||
$pathShared = trim($_REQUEST['pathShared']);
|
$pathShared = trim($_REQUEST['pathShared']);
|
||||||
$pathXmlforms = trim($_REQUEST['pathXmlforms']);
|
|
||||||
$adminPassword = trim($_REQUEST['adminPassword']);
|
$adminPassword = trim($_REQUEST['adminPassword']);
|
||||||
$adminPassword = $filter->validateInput($adminPassword);
|
$adminPassword = $filter->validateInput($adminPassword);
|
||||||
$adminUsername = trim($_REQUEST['adminUsername']);
|
$adminUsername = trim($_REQUEST['adminUsername']);
|
||||||
$adminUsername = $filter->validateInput($adminUsername);
|
$adminUsername = $filter->validateInput($adminUsername);
|
||||||
$deleteDB = ($_REQUEST['deleteDB'] == 'true');
|
$deleteDB = $_REQUEST['deleteDB'] === 'true';
|
||||||
$userLogged = (isset($_REQUEST['userLogged']) ? ($_REQUEST['userLogged'] == 'true') : false);
|
$userLogged = isset($_REQUEST['userLogged']) ? $_REQUEST['userLogged'] === 'true' : false;
|
||||||
$userLogged = $filter->validateInput($userLogged);
|
$userLogged = $filter->validateInput($userLogged);
|
||||||
|
|
||||||
if (substr($pathShared, -1) != '/') {
|
if (substr($pathShared, -1) !== '/') {
|
||||||
$pathShared .= '/';
|
$pathShared .= '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->installLog('-------------------------------------------');
|
$this->installLog('-------------------------------------------');
|
||||||
$this->installLog(G::LoadTranslation('ID_CREATING_WORKSPACE', SYS_LANG, array($workspace)));
|
$this->installLog(G::LoadTranslation('ID_CREATING_WORKSPACE', SYS_LANG, [$workspace]));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
self::setNewConnection(self::CONNECTION_TEST_INSTALL, $db_hostname, $db_username, $db_password, '', $db_port);
|
||||||
$db_host = ($db_port != '' && $db_port != 3306) ? $db_hostname . ':' . $db_port : $db_hostname;
|
$db_host = ($db_port != '' && $db_port != 3306) ? $db_hostname . ':' . $db_port : $db_hostname;
|
||||||
$this->link = mysqli_connect($db_host, $db_username, $db_password);
|
|
||||||
|
|
||||||
mysqli_set_charset($this->link, 'utf8');
|
$this->installLog(G::LoadTranslation('ID_CONNECT_TO_SERVER', SYS_LANG, [$db_hostname, $db_port, $db_username]));
|
||||||
$this->installLog(G::LoadTranslation('ID_CONNECT_TO_SERVER', SYS_LANG, array($db_hostname, $db_port, $db_username)));
|
|
||||||
|
|
||||||
if ($deleteDB) {
|
if ($deleteDB) {
|
||||||
$q = sprintf('DROP DATABASE IF EXISTS %s;', $wf, $wf);
|
$query = sprintf('DROP DATABASE IF EXISTS %s', $wf);
|
||||||
$this->mysqlQuery($q);
|
DB::connection(self::CONNECTION_TEST_INSTALL)->statement($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CREATE databases wf_workflow, rb_workflow and rp_workflow
|
// CREATE databases wf_workflow
|
||||||
$q = sprintf('CREATE DATABASE IF NOT EXISTS %s;', $wf, $wf);
|
DB::connection(self::CONNECTION_TEST_INSTALL)
|
||||||
$this->mysqlQuery($q);
|
->statement("CREATE DATABASE IF NOT EXISTS $wf");
|
||||||
|
|
||||||
|
self::setNewConnection(self::CONNECTION_INSTALL, $db_hostname, $db_username, $db_password, $wf, $db_port);
|
||||||
|
|
||||||
// CREATE users and GRANT Privileges
|
// CREATE users and GRANT Privileges
|
||||||
$wf_workspace = $wf;
|
$wf_workspace = $wf;
|
||||||
$wfGrantUser = uniqid('wf_');
|
$wfGrantUser = uniqid('wf_');
|
||||||
$rb_workspace = $wf;
|
|
||||||
$rp_workspace = $wf;
|
|
||||||
if (!$userLogged) {
|
if (!$userLogged) {
|
||||||
$wfPass = G::generate_password(15);
|
$wfPass = G::generate_password(15);
|
||||||
$this->setGrantPrivilegesMySQL($wfGrantUser, $wfPass, $wf, $db_hostname);
|
$this->setGrantPrivilegesMySQL($wfGrantUser, $wfPass, $wf, $db_hostname);
|
||||||
$this->setGrantPrivilegesMySQL($wfGrantUser, $wfPass, $wf, $db_hostname);
|
|
||||||
$this->setGrantPrivilegesMySQL($wfGrantUser, $wfPass, $wf, $db_hostname);
|
|
||||||
} else {
|
} else {
|
||||||
$wfPass = $db_password;
|
$wfPass = $db_password;
|
||||||
$rbPass = $db_password;
|
|
||||||
$rpPass = $db_password;
|
|
||||||
$wf = $db_username;
|
$wf = $db_username;
|
||||||
$wfGrantUser = $db_username;
|
$wfGrantUser = $db_username;
|
||||||
$rb = $db_username;
|
|
||||||
$rp = $db_username;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Generate the db.php file and folders
|
// Generate the db.php file and folders
|
||||||
$pathSharedSites = $pathShared;
|
$path_site = $pathShared . '/sites/' . $workspace . '/';
|
||||||
$path_site = $pathShared . "/sites/" . $workspace . "/";
|
|
||||||
|
|
||||||
@mkdir($path_site, 0777, true);
|
@mkdir($path_site, 0777, true);
|
||||||
@mkdir($path_site . "files/", 0777, true);
|
@mkdir($path_site . 'files/', 0777, true);
|
||||||
@mkdir($path_site . "mailTemplates/", 0777, true);
|
@mkdir($path_site . 'mailTemplates/', 0777, true);
|
||||||
@mkdir($path_site . "public/", 0777, true);
|
@mkdir($path_site . 'public/', 0777, true);
|
||||||
@mkdir($path_site . "reports/", 0777, true);
|
@mkdir($path_site . 'reports/', 0777, true);
|
||||||
@mkdir($path_site . "xmlForms", 0777, true);
|
@mkdir($path_site . 'xmlForms', 0777, true);
|
||||||
|
|
||||||
$db_file = $path_site . 'db.php';
|
$db_file = $path_site . 'db.php';
|
||||||
$dbText = "<?php\n";
|
$dbText = "<?php\n";
|
||||||
@@ -816,13 +843,13 @@ class InstallerModule extends Controller
|
|||||||
|
|
||||||
if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) {
|
if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) {
|
||||||
$dbText .= "\n";
|
$dbText .= "\n";
|
||||||
$dbText .= " define ('PARTNER_FLAG', " . ((defined('PARTNER_FLAG')) ? PARTNER_FLAG : ((isset($_REQUEST['PARTNER_FLAG'])) ? $_REQUEST['PARTNER_FLAG'] : 'false')) . ");\n";
|
$dbText .= " define ('PARTNER_FLAG', " . (defined('PARTNER_FLAG') ? PARTNER_FLAG : isset($_REQUEST['PARTNER_FLAG']) ? $_REQUEST['PARTNER_FLAG'] : 'false') . ");\n";
|
||||||
if ($this->systemName != '') {
|
if (!empty($this->systemName)) {
|
||||||
$dbText .= " define ('SYSTEM_NAME', '" . $this->systemName . "');\n";
|
$dbText .= " define ('SYSTEM_NAME', '" . $this->systemName . "');\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->installLog(G::LoadTranslation('ID_CREATING', SYS_LANG, array($db_file)));
|
$this->installLog(G::LoadTranslation('ID_CREATING', SYS_LANG, [$db_file]));
|
||||||
file_put_contents($db_file, $dbText);
|
file_put_contents($db_file, $dbText);
|
||||||
|
|
||||||
/*----------------------------------********---------------------------------*/
|
/*----------------------------------********---------------------------------*/
|
||||||
@@ -854,15 +881,8 @@ class InstallerModule extends Controller
|
|||||||
$this->installLog(G::LoadTranslation('ID_CREATING', SYS_LANG, array($databases_file)));
|
$this->installLog(G::LoadTranslation('ID_CREATING', SYS_LANG, array($databases_file)));
|
||||||
file_put_contents($databases_file, $databasesText);
|
file_put_contents($databases_file, $databasesText);
|
||||||
|
|
||||||
// Execute scripts to create and populates databases
|
|
||||||
$query = sprintf("USE %s;", $wf_workspace);
|
|
||||||
$this->mysqlQuery($query);
|
|
||||||
|
|
||||||
$this->mysqlFileQuery(PATH_RBAC_HOME . 'engine/data/mysql/schema.sql');
|
$this->mysqlFileQuery(PATH_RBAC_HOME . 'engine/data/mysql/schema.sql');
|
||||||
$this->mysqlFileQuery(PATH_RBAC_HOME . 'engine/data/mysql/insert.sql');
|
$this->mysqlFileQuery(PATH_RBAC_HOME . 'engine/data/mysql/insert.sql');
|
||||||
|
|
||||||
$query = sprintf("USE %s;", $wf_workspace);
|
|
||||||
$this->mysqlQuery($query);
|
|
||||||
$this->mysqlFileQuery(PATH_HOME . 'engine/data/mysql/schema.sql');
|
$this->mysqlFileQuery(PATH_HOME . 'engine/data/mysql/schema.sql');
|
||||||
$this->mysqlFileQuery(PATH_HOME . 'engine/data/mysql/insert.sql');
|
$this->mysqlFileQuery(PATH_HOME . 'engine/data/mysql/insert.sql');
|
||||||
|
|
||||||
@@ -877,61 +897,86 @@ class InstallerModule extends Controller
|
|||||||
file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql') &&
|
file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql') &&
|
||||||
file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql') &&
|
file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql') &&
|
||||||
file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql')) {
|
file_exists(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql')) {
|
||||||
$this->mysqlQuery($this->file_get_contents_utf8(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql'));
|
DB::connection(self::CONNECTION_INSTALL)->raw(file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationInsert.sql'));
|
||||||
$this->mysqlQuery($this->file_get_contents_utf8(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql'));
|
DB::connection(self::CONNECTION_INSTALL)->raw(file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerAppDelegationUpdate.sql'));
|
||||||
$this->mysqlQuery($this->file_get_contents_utf8(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql'));
|
DB::connection(self::CONNECTION_INSTALL)->raw(file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationUpdate.sql'));
|
||||||
$this->mysqlQuery($this->file_get_contents_utf8(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql'));
|
DB::connection(self::CONNECTION_INSTALL)->raw(file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerApplicationDelete.sql'));
|
||||||
$this->mysqlQuery($this->file_get_contents_utf8(PATH_HOME . "engine/methods/setup/setupSchemas/triggerSubApplicationInsert.sql"));
|
DB::connection(self::CONNECTION_INSTALL)->raw(file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerSubApplicationInsert.sql'));
|
||||||
$this->mysqlQuery($this->file_get_contents_utf8(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql'));
|
DB::connection(self::CONNECTION_INSTALL)->raw(file_get_contents(PATH_HOME . 'engine/methods/setup/setupSchemas/triggerContentUpdate.sql'));
|
||||||
|
|
||||||
$this->mysqlQuery("INSERT INTO `CONFIGURATION` (
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
`CFG_UID`,
|
->table('CONFIGURATION')
|
||||||
`CFG_VALUE`
|
->insert([
|
||||||
)
|
'CFG_UID' => 'APP_CACHE_VIEW_ENGINE',
|
||||||
VALUES (
|
'CFG_VALUE' => serialize(['LANG' => 'en', 'STATUS' => 'active'])
|
||||||
'APP_CACHE_VIEW_ENGINE',
|
]);
|
||||||
'" . mysqli_real_escape_string(serialize(array('LANG' => 'en', 'STATUS' => 'active'
|
|
||||||
))) . "'
|
|
||||||
)");
|
|
||||||
|
|
||||||
$this->mysqlQuery("INSERT INTO EMAIL_SERVER(MESS_UID, MESS_ENGINE) VALUES('" . \ProcessMaker\Util\Common::generateUID() . "', 'MAIL')");
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
|
->table('EMAIL_SERVER')
|
||||||
|
->insert([
|
||||||
|
'MESS_UID' => Common::generateUID(),
|
||||||
|
'MESS_ENGINE' => 'MAIL'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change admin user
|
// Change admin user
|
||||||
$query = sprintf("USE %s;", $wf_workspace);
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
$this->mysqlQuery($query);
|
->table('USERS')
|
||||||
|
->where('USR_UID', '00000000000000000000000000000001')
|
||||||
$query = sprintf("UPDATE USERS SET USR_USERNAME = '%s', USR_LASTNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, $adminUsername, G::encryptHash($adminPassword));
|
->update([
|
||||||
$this->mysqlQuery($query);
|
'USR_USERNAME' => $adminUsername,
|
||||||
|
'USR_LASTNAME' => $adminUsername,
|
||||||
$query = sprintf("UPDATE RBAC_USERS SET USR_USERNAME = '%s', USR_LASTNAME = '%s', USR_PASSWORD = '%s' WHERE USR_UID = '00000000000000000000000000000001' ", $adminUsername, $adminUsername, G::encryptHash($adminPassword));
|
'USR_PASSWORD' => Bootstrap::hashPassword($adminPassword, Bootstrap::hashBcrypt)
|
||||||
$this->mysqlQuery($query);
|
]);
|
||||||
|
|
||||||
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
|
->table('RBAC_USERS')
|
||||||
|
->where('USR_UID', '00000000000000000000000000000001')
|
||||||
|
->update([
|
||||||
|
'USR_USERNAME' => $adminUsername,
|
||||||
|
'USR_LASTNAME' => $adminUsername,
|
||||||
|
'USR_PASSWORD' => Bootstrap::hashPassword($adminPassword, Bootstrap::hashBcrypt)
|
||||||
|
]);
|
||||||
// Write the paths_installed.php file (contains all the information configured so far)
|
// Write the paths_installed.php file (contains all the information configured so far)
|
||||||
if (!file_exists(FILE_PATHS_INSTALLED)) {
|
if (!file_exists(FILE_PATHS_INSTALLED)) {
|
||||||
$sh = G::encryptOld(filemtime(PATH_GULLIVER . '/class.g.php'));
|
$sh = G::encryptOld(filemtime(PATH_GULLIVER . '/class.g.php'));
|
||||||
$h = G::encrypt($db_hostname . $sh . $db_username . $sh . $db_password, $sh);
|
$h = G::encrypt($db_host . $sh . $db_username . $sh . $db_password, $sh);
|
||||||
$dbText = "<?php\n";
|
$dbText = "<?php\n";
|
||||||
$dbText .= sprintf(" define('PATH_DATA', '%s');\n", $pathShared);
|
$dbText .= sprintf(" define('PATH_DATA', '%s');\n", $pathShared);
|
||||||
$dbText .= sprintf(" define('PATH_C', '%s');\n", $pathShared . 'compiled/');
|
$dbText .= sprintf(" define('PATH_C', '%s');\n", $pathShared . 'compiled/');
|
||||||
$dbText .= sprintf(" define('HASH_INSTALLATION', '%s');\n", $h);
|
$dbText .= sprintf(" define('HASH_INSTALLATION', '%s');\n", $h);
|
||||||
$dbText .= sprintf(" define('SYSTEM_HASH', '%s');\n", $sh);
|
$dbText .= sprintf(" define('SYSTEM_HASH', '%s');\n", $sh);
|
||||||
$this->installLog(G::LoadTranslation('ID_CREATING', SYS_LANG, array(FILE_PATHS_INSTALLED)));
|
$this->installLog(G::LoadTranslation('ID_CREATING', SYS_LANG, [FILE_PATHS_INSTALLED]));
|
||||||
file_put_contents(FILE_PATHS_INSTALLED, $dbText);
|
file_put_contents(FILE_PATHS_INSTALLED, $dbText);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AppCacheView Build
|
* AppCacheView Build
|
||||||
*/
|
*/
|
||||||
define( 'HASH_INSTALLATION', $h );
|
define('HASH_INSTALLATION', $h);
|
||||||
define( 'SYSTEM_HASH', $sh );
|
define('SYSTEM_HASH', $sh);
|
||||||
define( 'PATH_DB', $pathShared . 'sites' . PATH_SEP );
|
define('PATH_DB', $pathShared . 'sites' . PATH_SEP);
|
||||||
define( 'SYS_SYS', $workspace );
|
define('SYS_SYS', $workspace);
|
||||||
config(["system.workspace" => $workspace]);
|
config(['system.workspace' => $workspace]);
|
||||||
|
|
||||||
require_once("propel/Propel.php");
|
System::setConnectionConfig(
|
||||||
|
'mysql',
|
||||||
|
$db_host,
|
||||||
|
$wf_workspace,
|
||||||
|
$wfGrantUser,
|
||||||
|
$wfPass,
|
||||||
|
$db_host,
|
||||||
|
$wf_workspace,
|
||||||
|
$wfGrantUser,
|
||||||
|
$wfPass,
|
||||||
|
$db_host,
|
||||||
|
$wf_workspace,
|
||||||
|
$wfGrantUser,
|
||||||
|
$wfPass);
|
||||||
|
|
||||||
Propel::init(PATH_CORE . "config/databases.php");
|
require_once('propel/Propel.php');
|
||||||
|
|
||||||
|
Propel::init(PATH_CORE . 'config/databases.php');
|
||||||
$con = Propel::getConnection('workflow');
|
$con = Propel::getConnection('workflow');
|
||||||
|
|
||||||
require_once('classes/model/AppCacheView.php');
|
require_once('classes/model/AppCacheView.php');
|
||||||
@@ -990,8 +1035,8 @@ class InstallerModule extends Controller
|
|||||||
$info->uri = PATH_SEP . 'sys' . $_REQUEST['workspace'] . PATH_SEP . $langUri . PATH_SEP . $skinUri . PATH_SEP . 'login' . PATH_SEP . 'login';
|
$info->uri = PATH_SEP . 'sys' . $_REQUEST['workspace'] . PATH_SEP . $langUri . PATH_SEP . $skinUri . PATH_SEP . 'login' . PATH_SEP . 'login';
|
||||||
|
|
||||||
//register PMDesigner Client
|
//register PMDesigner Client
|
||||||
$http = (G::is_https() == true) ? 'https' : 'http';
|
$http = G::is_https() ? 'https' : 'http';
|
||||||
$host = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '');
|
$host = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] !== '80' ? ':' . $_SERVER['SERVER_PORT'] : '');
|
||||||
|
|
||||||
$endpoint = sprintf(
|
$endpoint = sprintf(
|
||||||
'%s://%s/sys%s/%s/%s/oauth2/grant',
|
'%s://%s/sys%s/%s/%s/oauth2/grant',
|
||||||
@@ -1003,15 +1048,17 @@ class InstallerModule extends Controller
|
|||||||
);
|
);
|
||||||
|
|
||||||
// inserting the outh_client
|
// inserting the outh_client
|
||||||
if (!$userLogged) {
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
$query = sprintf("USE %s;", $wf);
|
->table('OAUTH_CLIENTS')
|
||||||
} else {
|
->insert([
|
||||||
$query = sprintf("USE %s;", trim($_REQUEST['wfDatabase']));
|
'CLIENT_ID' => 'x-pm-local-client',
|
||||||
}
|
'CLIENT_SECRET' => '179ad45c6ce2cb97cf1029e212046e81',
|
||||||
$this->mysqlQuery($query);
|
'CLIENT_NAME' => 'PM Web Designer',
|
||||||
$query = ("INSERT INTO OAUTH_CLIENTS (CLIENT_ID,CLIENT_SECRET,CLIENT_NAME,CLIENT_DESCRIPTION,CLIENT_WEBSITE,REDIRECT_URI,USR_UID ) VALUES
|
'CLIENT_DESCRIPTION' => 'ProcessMaker Web Designer App',
|
||||||
('x-pm-local-client','179ad45c6ce2cb97cf1029e212046e81','PM Web Designer','ProcessMaker Web Designer App','www.processmaker.com','" . $endpoint . "','00000000000000000000000000000001' )");
|
'CLIENT_WEBSITE' => 'www.processmaker.com',
|
||||||
$this->mysqlQuery($query);
|
'REDIRECT_URI' => $endpoint,
|
||||||
|
'USR_UID' => '00000000000000000000000000000001'
|
||||||
|
]);
|
||||||
|
|
||||||
$indexFileUpdated = true;
|
$indexFileUpdated = true;
|
||||||
if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) {
|
if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) {
|
||||||
@@ -1021,30 +1068,30 @@ class InstallerModule extends Controller
|
|||||||
G::update_php_ini($envFile, $updatedConf);
|
G::update_php_ini($envFile, $updatedConf);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$info->result = false;
|
$info->result = false;
|
||||||
$info->message = G::LoadTranslation('ID_PROCESSMAKER_WRITE_CONFIG_INDEX', SYS_LANG, array($envFile));
|
$info->message = G::LoadTranslation('ID_PROCESSMAKER_WRITE_CONFIG_INDEX', SYS_LANG, [$envFile]);
|
||||||
$info->message .= G::LoadTranslation('ID_PROCESSMAKER_UI_NOT_INSTALL');
|
$info->message .= G::LoadTranslation('ID_PROCESSMAKER_UI_NOT_INSTALL');
|
||||||
$this->installLog(G::LoadTranslation('ID_INSTALL_BUT_ERROR', SYS_LANG, array('env.ini')));
|
$this->installLog(G::LoadTranslation('ID_INSTALL_BUT_ERROR', SYS_LANG, ['env.ini']));
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// update the main index file
|
// update the main index file
|
||||||
$indexFileUpdated = System::updateIndexFile(array('lang' => 'en', 'skin' => $updatedConf['default_skin']));
|
$indexFileUpdated = System::updateIndexFile(['lang' => 'en', 'skin' => $updatedConf['default_skin']]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$info->result = false;
|
$info->result = false;
|
||||||
$info->message = G::LoadTranslation('ID_PROCESSMAKER_WRITE_CONFIG_INDEX', SYS_LANG, array(PATH_HTML . "index.html."));
|
$info->message = G::LoadTranslation('ID_PROCESSMAKER_WRITE_CONFIG_INDEX', SYS_LANG, [PATH_HTML . "index.html."]);
|
||||||
$info->message .= G::LoadTranslation('ID_PROCESSMAKER_UI_NOT_INSTALL');
|
$info->message .= G::LoadTranslation('ID_PROCESSMAKER_UI_NOT_INSTALL');
|
||||||
$this->installLog(G::LoadTranslation('ID_INSTALL_BUT_ERROR', SYS_LANG, array('index.html')));
|
$this->installLog(G::LoadTranslation('ID_INSTALL_BUT_ERROR', SYS_LANG, ['index.html']));
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->installLog(G::LoadTranslation('ID_INDEX_FILE_UPDATED', SYS_LANG, array($indexFileUpdated, $sysConf['default_lang'], $sysConf['default_skin'])));
|
$this->installLog(G::LoadTranslation('ID_INDEX_FILE_UPDATED', SYS_LANG, [$indexFileUpdated, $sysConf['default_lang'], $sysConf['default_skin']]));
|
||||||
$this->installLog(G::LoadTranslation('ID_INSTALL_SUCESS'));
|
$this->installLog(G::LoadTranslation('ID_INSTALL_SUCESS'));
|
||||||
|
|
||||||
$info->result = true;
|
$info->result = true;
|
||||||
$info->message = G::LoadTranslation('ID_INSTALL_SUCESS');
|
$info->message = G::LoadTranslation('ID_INSTALL_SUCESS');
|
||||||
$info->messageFinish = G::LoadTranslation('ID_PROCESSMAKER_SUCCESS_INSTALLED', SYS_LANG, array($workspace));;
|
$info->messageFinish = G::LoadTranslation('ID_PROCESSMAKER_SUCCESS_INSTALLED', SYS_LANG, [$workspace]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$info->canRedirect = false;
|
$info->canRedirect = false;
|
||||||
$info->result = false;
|
$info->result = false;
|
||||||
@@ -1185,7 +1232,7 @@ class InstallerModule extends Controller
|
|||||||
$this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationUpdate.sql'));
|
$this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerAppDelegationUpdate.sql'));
|
||||||
$this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationUpdate.sql'));
|
$this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationUpdate.sql'));
|
||||||
$this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationDelete.sql'));
|
$this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerApplicationDelete.sql'));
|
||||||
$this->mysqlQuery(@file_get_contents(PATH_HOME . "engine/methods/setup/setupSchemas/triggerSubApplicationInsert.sql"));
|
$this->mssqlQuery(@file_get_contents(PATH_HOME . "engine/methods/setup/setupSchemas/triggerSubApplicationInsert.sql"));
|
||||||
$this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerContentUpdate.sql'));
|
$this->mssqlQuery(@file_get_contents(PATH_HOME . 'engine/plugins/enterprise/data/triggerContentUpdate.sql'));
|
||||||
$this->mssqlQuery("INSERT INTO CONFIGURATION (
|
$this->mssqlQuery("INSERT INTO CONFIGURATION (
|
||||||
CFG_UID,
|
CFG_UID,
|
||||||
@@ -1197,7 +1244,7 @@ class InstallerModule extends Controller
|
|||||||
))) . "'
|
))) . "'
|
||||||
)");
|
)");
|
||||||
|
|
||||||
$this->mssqlQuery("INSERT INTO EMAIL_SERVER(MESS_UID, MESS_ENGINE) VALUES('" . \ProcessMaker\Util\Common::generateUID() . "','MAIL')");
|
$this->mssqlQuery("INSERT INTO EMAIL_SERVER(MESS_UID, MESS_ENGINE) VALUES('" . Common::generateUID() . "','MAIL')");
|
||||||
}
|
}
|
||||||
|
|
||||||
//change admin user
|
//change admin user
|
||||||
@@ -1230,7 +1277,6 @@ class InstallerModule extends Controller
|
|||||||
$info->message = G::LoadTranslation('ID_INSTALL_SUCESS');
|
$info->message = G::LoadTranslation('ID_INSTALL_SUCESS');
|
||||||
$info->url = '/sys' . $_REQUEST['workspace'] . '/en/neoclassic/login/login';
|
$info->url = '/sys' . $_REQUEST['workspace'] . '/en/neoclassic/login/login';
|
||||||
$info->messageFinish = G::LoadTranslation('ID_PROCESSMAKER_SUCCESS_INSTALLED', SYS_LANG, array($workspace));
|
$info->messageFinish = G::LoadTranslation('ID_PROCESSMAKER_SUCCESS_INSTALLED', SYS_LANG, array($workspace));
|
||||||
;
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$info->result = false;
|
$info->result = false;
|
||||||
$info->message = $e->getMessage();
|
$info->message = $e->getMessage();
|
||||||
@@ -1254,10 +1300,15 @@ class InstallerModule extends Controller
|
|||||||
return $systemName;
|
return $systemName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Database engines list
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
public function getEngines()
|
public function getEngines()
|
||||||
{
|
{
|
||||||
$this->setResponseType('json');
|
$this->setResponseType('json');
|
||||||
$engines = array();
|
$engines = [];
|
||||||
if (function_exists('mysqli_query')) {
|
if (function_exists('mysqli_query')) {
|
||||||
$engine = new stdclass();
|
$engine = new stdclass();
|
||||||
$engine->id = 'mysql';
|
$engine->id = 'mysql';
|
||||||
@@ -1290,15 +1341,13 @@ class InstallerModule extends Controller
|
|||||||
|
|
||||||
switch ($_REQUEST['db_engine']) {
|
switch ($_REQUEST['db_engine']) {
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
if ($db_port !== '3306') {
|
|
||||||
$db_hostname = $db_hostname . ':' . $db_port;
|
|
||||||
}
|
|
||||||
$wfDatabase = $filter->validateInput($_REQUEST['wfDatabase'], 'nosql');
|
$wfDatabase = $filter->validateInput($_REQUEST['wfDatabase'], 'nosql');
|
||||||
$link = mysqli_connect($db_hostname, $db_username, $db_password, $wfDatabase);
|
|
||||||
$query = "show databases like '%s' ";
|
self::setNewConnection(self::CONNECTION_TEST_INSTALL, $db_hostname, $db_username, $db_password, '', $db_port);
|
||||||
$query = $filter->preventSqlInjection($query, array($wfDatabase), $link);
|
$response = DB::connection(self::CONNECTION_TEST_INSTALL)
|
||||||
$dataSet = mysqli_query($link, $query);
|
->select("show databases like '$wfDatabase'");
|
||||||
$info->wfDatabaseExists = (mysqli_num_rows($dataSet) > 0);
|
|
||||||
|
$info->wfDatabaseExists = count($response) > 0;
|
||||||
break;
|
break;
|
||||||
case 'mssql':
|
case 'mssql':
|
||||||
$link = @mssql_connect($db_hostname, $db_username, $db_password);
|
$link = @mssql_connect($db_hostname, $db_username, $db_password);
|
||||||
@@ -1332,51 +1381,53 @@ class InstallerModule extends Controller
|
|||||||
|
|
||||||
private function testMySQLConnection()
|
private function testMySQLConnection()
|
||||||
{
|
{
|
||||||
$filter = new InputFilter();
|
try {
|
||||||
$info = new StdClass();
|
$filter = new InputFilter();
|
||||||
$info->result = false;
|
$info = new StdClass();
|
||||||
$info->message = '';
|
$info->result = false;
|
||||||
if (!function_exists('mysqli_connect')) {
|
$info->message = '';
|
||||||
$info->message = G::LoadTranslation('ID_PHP_MYSQLI_NOT_INSTALL');
|
if (!function_exists('mysqli_connect')) {
|
||||||
return $info;
|
$info->message = G::LoadTranslation('ID_PHP_MYSQLI_NOT_INSTALL');
|
||||||
}
|
return $info;
|
||||||
$dataRequest = $_REQUEST;
|
}
|
||||||
$db_hostname = $filter->validateInput($dataRequest['db_hostname']);
|
$dataRequest = $_REQUEST;
|
||||||
$db_port = $filter->validateInput($dataRequest['db_port']);
|
$db_hostname = $filter->validateInput($dataRequest['db_hostname']);
|
||||||
$db_username = $filter->validateInput($dataRequest['db_username']);
|
$db_port = $filter->validateInput($dataRequest['db_port']);
|
||||||
$db_password = urlencode($dataRequest['db_password']);
|
$db_username = $filter->validateInput($dataRequest['db_username']);
|
||||||
$db_password = urldecode($filter->validateInput($db_password));
|
$db_password = urlencode($dataRequest['db_password']);
|
||||||
$fp = @fsockopen($db_hostname, $db_port, $errno, $errstr, 30);
|
$db_password = urldecode($filter->validateInput($db_password));
|
||||||
if (!$fp) {
|
$fp = @fsockopen($db_hostname, $db_port, $errno, $errstr, 30);
|
||||||
$info->message .= G::LoadTranslation('ID_CONNECTION_ERROR', SYS_LANG, array("$errstr ($errno)"));
|
if (!$fp) {
|
||||||
return $info;
|
$info->message .= G::LoadTranslation('ID_CONNECTION_ERROR', SYS_LANG, ["$errstr ($errno)"]);
|
||||||
}
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
$db_host = ($db_port !== '' && $db_port !== 1433) ? $db_hostname . ':' . $db_port : $db_hostname;
|
$db_username = $filter->validateInput($db_username, 'nosql');
|
||||||
|
$db_hostname = $filter->validateInput($db_hostname, 'nosql');
|
||||||
|
|
||||||
$link = new mysqli($db_host, $db_username, $db_password);
|
self::setNewConnection(self::CONNECTION_TEST_INSTALL, $db_hostname, $db_username, $db_password, '', $db_port);
|
||||||
if ($link->connect_error) {
|
$query = "SELECT * FROM `information_schema`.`USER_PRIVILEGES` where (GRANTEE = \"'$db_username'@'$db_hostname'\" OR GRANTEE = \"'$db_username'@'%%'\") ";
|
||||||
$info->message .= G::LoadTranslation('ID_MYSQL_CREDENTIALS_WRONG');
|
|
||||||
return $info;
|
$response = DB::connection(self::CONNECTION_TEST_INSTALL)->select($query);
|
||||||
|
|
||||||
|
if (!is_array($response)) {
|
||||||
|
$info->message .= G::LoadTranslation('ID_CONNECTION_ERROR_PRIVILEGE', SYS_LANG, [$db_username]);
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
$info->message .= G::LoadTranslation('ID_MYSQL_SUCCESS_CONNECT');
|
||||||
|
$info->result = true;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$info->result = false;
|
||||||
|
$info->message = G::LoadTranslation('ID_MYSQL_CREDENTIALS_WRONG');
|
||||||
}
|
}
|
||||||
$db_username = $filter->validateInput($db_username, 'nosql');
|
|
||||||
$db_hostname = $filter->validateInput($db_hostname, 'nosql');
|
|
||||||
$query = "SELECT * FROM `information_schema`.`USER_PRIVILEGES` where (GRANTEE = \"'%s'@'%s'\" OR GRANTEE = \"'%s'@'%%'\") ";
|
|
||||||
$query = $filter->preventSqlInjection($query, array($db_username, $db_hostname, $db_username), $link);
|
|
||||||
$res = $link->query($query);
|
|
||||||
$row = $res->fetch_array();
|
|
||||||
$hasSuper = is_array($row);
|
|
||||||
$res->free();
|
|
||||||
$link->close();
|
|
||||||
if (!$hasSuper) {
|
|
||||||
$info->message .= G::LoadTranslation('ID_CONNECTION_ERROR_PRIVILEGE', SYS_LANG, array($db_username));
|
|
||||||
return $info;
|
|
||||||
}
|
|
||||||
$info->message .= G::LoadTranslation('ID_MYSQL_SUCCESS_CONNECT');
|
|
||||||
$info->result = true;
|
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function test a SQL Server connection
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
private function testMSSQLConnection()
|
private function testMSSQLConnection()
|
||||||
{
|
{
|
||||||
$filter = new InputFilter();
|
$filter = new InputFilter();
|
||||||
@@ -1400,6 +1451,7 @@ class InstallerModule extends Controller
|
|||||||
$info->message .= G::LoadTranslation('ID_CONNECTION_ERROR', SYS_LANG, array("$errstr ($errno)"));
|
$info->message .= G::LoadTranslation('ID_CONNECTION_ERROR', SYS_LANG, array("$errstr ($errno)"));
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
\Illuminate\Support\Facades\DB::connection();
|
||||||
|
|
||||||
$db_host = ($db_port != '' && $db_port != 1433) ? $db_hostname . ':' . $db_port : $db_hostname;
|
$db_host = ($db_port != '' && $db_port != 1433) ? $db_hostname . ':' . $db_port : $db_hostname;
|
||||||
|
|
||||||
@@ -1454,13 +1506,18 @@ class InstallerModule extends Controller
|
|||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPartner()
|
/**
|
||||||
|
* This function define the partner behaviour when the PARTNER_FLAG is defined
|
||||||
|
* Execute to change of skin
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function setPartner()
|
||||||
{
|
{
|
||||||
if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) {
|
if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) {
|
||||||
// Execute sql for partner
|
// Execute sql for partner
|
||||||
$pathMysqlPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'mysql' . PATH_SEP;
|
$pathMysqlPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'mysql' . PATH_SEP;
|
||||||
if (G::verifyPath($pathMysqlPartner)) {
|
if (G::verifyPath($pathMysqlPartner)) {
|
||||||
$res = array();
|
|
||||||
$filesSlq = glob($pathMysqlPartner . '*.sql');
|
$filesSlq = glob($pathMysqlPartner . '*.sql');
|
||||||
foreach ($filesSlq as $value) {
|
foreach ($filesSlq as $value) {
|
||||||
$this->mysqlFileQuery($value);
|
$this->mysqlFileQuery($value);
|
||||||
@@ -1470,7 +1527,6 @@ class InstallerModule extends Controller
|
|||||||
// Execute to change of skin
|
// Execute to change of skin
|
||||||
$pathSkinPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'skin' . PATH_SEP;
|
$pathSkinPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'skin' . PATH_SEP;
|
||||||
if (G::verifyPath($pathSkinPartner)) {
|
if (G::verifyPath($pathSkinPartner)) {
|
||||||
$res = array();
|
|
||||||
$fileTar = glob($pathSkinPartner . '*.tar');
|
$fileTar = glob($pathSkinPartner . '*.tar');
|
||||||
foreach ($fileTar as $value) {
|
foreach ($fileTar as $value) {
|
||||||
$dataFile = pathinfo($value);
|
$dataFile = pathinfo($value);
|
||||||
@@ -1503,10 +1559,19 @@ class InstallerModule extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy a directory or file
|
||||||
|
*
|
||||||
|
* @param string $fromDir
|
||||||
|
* @param string $toDir
|
||||||
|
* @param integer $chmod
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function copyFile($fromDir, $toDir, $chmod = 0777)
|
public function copyFile($fromDir, $toDir, $chmod = 0777)
|
||||||
{
|
{
|
||||||
$errors = array();
|
$errors = [];
|
||||||
$messages = array();
|
$messages = [];
|
||||||
|
|
||||||
if (!is_writable($toDir)) {
|
if (!is_writable($toDir)) {
|
||||||
$errors[] = 'target ' . $toDir . ' is not writable';
|
$errors[] = 'target ' . $toDir . ' is not writable';
|
||||||
@@ -1546,32 +1611,33 @@ class InstallerModule extends Controller
|
|||||||
closedir($handle);
|
closedir($handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setConfiguration()
|
/**
|
||||||
{
|
* Define build Pattern Extras related to:
|
||||||
//a:4:{s:26:"login_enableForgotPassword";b:0;s:27:"login_enableVirtualKeyboard";b:0;s:21:"login_defaultLanguage";s:5:"pt-BR";s:10:"dateFormat";s:15:"d \\d\\e F \\d\\e Y";}
|
* Upload translation .po file
|
||||||
$value = array(
|
* Upload skin file
|
||||||
'login_defaultLanguage' => "pt-BR",
|
* Upload plugin file
|
||||||
"dateFormat" => 'd \d\e F \d\e Y'
|
* Active plugins to enterprise
|
||||||
);
|
*
|
||||||
|
* @param string $username
|
||||||
$value = serialize($value);
|
* @param string $password
|
||||||
$query = "INSERT INTO CONFIGURATION (CFG_UID, CFG_VALUE) VALUES ('ENVIRONMENT_SETTINGS', '" . mysqli_real_escape_string($this->link, $value) . "')";
|
* @param string $workspace
|
||||||
|
* @param string $lang
|
||||||
$this->mysqlQuery($query);
|
* @param string $skinName
|
||||||
}
|
*
|
||||||
|
* @return void
|
||||||
public function buildParternExtras($username, $password, $workspace, $lang, $skinName)
|
*/
|
||||||
|
private function buildParternExtras($username, $password, $workspace, $lang, $skinName)
|
||||||
{
|
{
|
||||||
$filter = new InputFilter();
|
$filter = new InputFilter();
|
||||||
ini_set('max_execution_time', '0');
|
ini_set('max_execution_time', '0');
|
||||||
ini_set('memory_limit', '256M');
|
ini_set('memory_limit', '256M');
|
||||||
|
|
||||||
$serv = 'http://';
|
$serv = 'http://';
|
||||||
if (isset($_SERVER['HTTPS']) && trim($_SERVER['HTTPS']) != '') {
|
if (isset($_SERVER['HTTPS']) && !empty(trim($_SERVER['HTTPS']))) {
|
||||||
$serv = 'https://';
|
$serv = 'https://';
|
||||||
}
|
}
|
||||||
$serv .= $_SERVER['SERVER_NAME'];
|
$serv .= $_SERVER['SERVER_NAME'];
|
||||||
if (isset($_SERVER['SERVER_PORT']) && trim($_SERVER['SERVER_PORT']) != '') {
|
if (isset($_SERVER['SERVER_PORT']) && !empty(trim($_SERVER['SERVER_PORT']))) {
|
||||||
$serv .= ':' . $_SERVER['SERVER_PORT'];
|
$serv .= ':' . $_SERVER['SERVER_PORT'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1610,7 +1676,7 @@ class InstallerModule extends Controller
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
$postData = array();
|
$postData = [];
|
||||||
// File to upload/post
|
// File to upload/post
|
||||||
|
|
||||||
$postData['form[LANGUAGE_FILENAME]'] = "@" . PATH_CORE . "content/translations/processmaker.$lang.po";
|
$postData['form[LANGUAGE_FILENAME]'] = "@" . PATH_CORE . "content/translations/processmaker.$lang.po";
|
||||||
@@ -1633,7 +1699,7 @@ class InstallerModule extends Controller
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
$postData = array();
|
$postData = [];
|
||||||
|
|
||||||
$skins = glob(PATH_CORE . "data/partner/*.tar");
|
$skins = glob(PATH_CORE . "data/partner/*.tar");
|
||||||
if (count($skins) > 0) {
|
if (count($skins) > 0) {
|
||||||
@@ -1666,7 +1732,7 @@ class InstallerModule extends Controller
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
$postData = array();
|
$postData = [];
|
||||||
// resolv the plugin name
|
// resolv the plugin name
|
||||||
$plugins = glob(PATH_CORE . "plugins/*.tar");
|
$plugins = glob(PATH_CORE . "plugins/*.tar");
|
||||||
if (count($plugins) > 0) {
|
if (count($plugins) > 0) {
|
||||||
@@ -1703,7 +1769,7 @@ class InstallerModule extends Controller
|
|||||||
foreach ($plugins as $value) {
|
foreach ($plugins as $value) {
|
||||||
$dataPlugin = pathinfo($value);
|
$dataPlugin = pathinfo($value);
|
||||||
$namePlugin = $dataPlugin['filename'];
|
$namePlugin = $dataPlugin['filename'];
|
||||||
if ($value != 'enterprise') {
|
if ($value !== 'enterprise') {
|
||||||
$db_hostname = trim($_REQUEST['db_hostname']);
|
$db_hostname = trim($_REQUEST['db_hostname']);
|
||||||
$db_hostname = $filter->validateInput($db_hostname);
|
$db_hostname = $filter->validateInput($db_hostname);
|
||||||
$db_port = trim($_REQUEST['db_port']);
|
$db_port = trim($_REQUEST['db_port']);
|
||||||
@@ -1717,12 +1783,15 @@ class InstallerModule extends Controller
|
|||||||
|
|
||||||
$db_host = ($db_port != '' && $db_port != 3306) ? $db_hostname . ':' . $db_port : $db_hostname;
|
$db_host = ($db_port != '' && $db_port != 3306) ? $db_hostname . ':' . $db_port : $db_hostname;
|
||||||
|
|
||||||
$link = mysqli_connect($db_host, $db_username, $db_password, $wf);
|
$row = DB::connection(self::CONNECTION_INSTALL)
|
||||||
mysqli_select_db($link, $wf);
|
->table('ADDONS_MANAGER')
|
||||||
$res = mysqli_query($link, "SELECT STORE_ID FROM ADDONS_MANAGER WHERE ADDON_NAME = '" . $namePlugin . "'");
|
->select('STORE_ID')
|
||||||
if ($row = mysqli_fetch_array($res)) {
|
->where('ADDON_NAME', $namePlugin)
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
if ($row) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
$postData = array();
|
$postData = [];
|
||||||
$postData['action'] = "enable";
|
$postData['action'] = "enable";
|
||||||
$postData['addon'] = $namePlugin;
|
$postData['addon'] = $namePlugin;
|
||||||
$postData['store'] = $row['STORE_ID'];
|
$postData['store'] = $row['STORE_ID'];
|
||||||
|
|||||||
@@ -1,64 +1,43 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* upgrade_SystemAjax.php
|
|
||||||
*
|
|
||||||
* ProcessMaker Open Source Edition
|
|
||||||
* Copyright (C) 2004 - 2010 Colosa Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
||||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
||||||
*/
|
|
||||||
global $DB_ADAPTER;
|
global $DB_ADAPTER;
|
||||||
global $DB_HOST;
|
global $DB_HOST;
|
||||||
global $DB_USER;
|
global $DB_USER;
|
||||||
global $DB_PASS;
|
global $DB_PASS;
|
||||||
global $DB_NAME;
|
global $DB_NAME;
|
||||||
set_time_limit( 0 );
|
set_time_limit(0);
|
||||||
|
|
||||||
$id = '';
|
$id = '';
|
||||||
if (isset( $_POST['id'] ))
|
if (isset($_POST['id']))
|
||||||
$id = $_POST['id'];
|
$id = $_POST['id'];
|
||||||
|
|
||||||
$aUpgradeData = unserialize( file_get_contents( PATH_DATA . 'log' . PATH_SEP . "upgrade.data.bin" ) );
|
$upgradeData = unserialize(file_get_contents(PATH_DATA . 'log' . PATH_SEP . "upgrade.data.bin"));
|
||||||
$aWorkspaces = $aUpgradeData['workspaces'];
|
$workspaces = $upgradeData['workspaces'];
|
||||||
|
|
||||||
if (is_array( $aWorkspaces ) && count( $aWorkspaces ) > 0) {
|
if (is_array($workspaces) && count($workspaces) > 0) {
|
||||||
$workspace = array_shift( $aUpgradeData['workspaces'] );
|
$workspace = array_shift($upgradeData['workspaces']);
|
||||||
|
|
||||||
eval( getDatabaseCredentials( PATH_DB . $workspace . PATH_SEP . 'db.php' ) );
|
eval(getDatabaseCredentials(PATH_DB . $workspace . PATH_SEP . 'db.php'));
|
||||||
$oDataBase = new database( $DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME );
|
$database = new database($DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
|
||||||
$oDataBase->iFetchType = MYSQL_NUM;
|
$database->iFetchType = MYSQLI_NUM;
|
||||||
|
|
||||||
//processing .po file
|
//processing .po file
|
||||||
if ($aUpgradeData['sPoFile'] != '') {
|
if (!empty($upgradeData['sPoFile'])) {
|
||||||
$oLanguages = new languages();
|
$oLanguages = new languages();
|
||||||
$oLanguages->importLanguage( $aUpgradeData['sPoFile'], $aUpgradeData['bForceXmlPoFile'] );
|
$oLanguages->importLanguage($upgradeData['sPoFile'], $upgradeData['bForceXmlPoFile']);
|
||||||
$aUpgradeData['bForceXmlPoFile'] = false;
|
$upgradeData['bForceXmlPoFile'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($aUpgradeData['sSchemaFile'] != '')
|
if ($upgradeData['sSchemaFile'] != '')
|
||||||
processMasterSchemaFile( $aUpgradeData['sSchemaFile'] );
|
processMasterSchemaFile($upgradeData['sSchemaFile']);
|
||||||
|
|
||||||
//draw a gauge control indicating the progress in workspaces
|
//draw a gauge control indicating the progress in workspaces
|
||||||
$gauge = intval( (($aUpgradeData['wsQuantity'] - count( $aWorkspaces ) + 1) / $aUpgradeData['wsQuantity']) * 301 );
|
$gauge = intval((($upgradeData['wsQuantity'] - count($workspaces) + 1) / $upgradeData['wsQuantity']) * 301);
|
||||||
print "<table cellpadding=0><tr><td><img src='/images/ajax-loader.gif' border=0/></td><td>";
|
print "<table cellpadding=0><tr><td><img src='/images/ajax-loader.gif' border=0/></td><td>";
|
||||||
print "<div style='border-style:solid;border-width:1px; border-color: #A1C868; width:300px; height:19px;' >";
|
print "<div style='border-style:solid;border-width:1px; border-color: #A1C868; width:300px; height:19px;' >";
|
||||||
print "<div style='color:#FFF; height:16px; text-align:center; padding-top:3px; background-image: url(/skins/green/images/bm.jpg); background-repeat: repeat-x; width: {$gauge}px' ></div> </div>";
|
print "<div style='color:#FFF; height:16px; text-align:center; padding-top:3px; background-image: url(/skins/green/images/bm.jpg); background-repeat: repeat-x; width: {$gauge}px' ></div> </div>";
|
||||||
print "</td><td width='40%'><font color=black> Upgrading the workspace </font><b><font color=green>".$filter->xssFilterHard($workspace)."</font></b></td><td width=250 align=right>| ".$filter->xssFilterHard($id)." Remaining</td></tr></table>";
|
print "</td><td width='40%'><font color=black> Upgrading the workspace </font><b><font color=green>" . $filter->xssFilterHard($workspace) . "</font></b></td><td width=250 align=right>| " . $filter->xssFilterHard($id) . " Remaining</td></tr></table>";
|
||||||
file_put_contents( PATH_DATA . 'log' . PATH_SEP . "upgrade.data.bin", serialize( $aUpgradeData ) );
|
file_put_contents(PATH_DATA . 'log' . PATH_SEP . "upgrade.data.bin", serialize($upgradeData));
|
||||||
} else {
|
} else {
|
||||||
print "<table cellpadding=0><tr><td> </td><td>";
|
print "<table cellpadding=0><tr><td> </td><td>";
|
||||||
print "<div style='border-style:solid;border-width:1px; border-color: #A1C868; width:300px; height:19px;' >";
|
print "<div style='border-style:solid;border-width:1px; border-color: #A1C868; width:300px; height:19px;' >";
|
||||||
@@ -68,92 +47,92 @@ if (is_array( $aWorkspaces ) && count( $aWorkspaces ) > 0) {
|
|||||||
|
|
||||||
die();
|
die();
|
||||||
|
|
||||||
function getDatabaseCredentials ($dbFile)
|
function getDatabaseCredentials($dbFile)
|
||||||
{
|
{
|
||||||
$sContent = file_get_contents( $dbFile );
|
$sContent = file_get_contents($dbFile);
|
||||||
$sContent = str_replace( '<?php', '', $sContent );
|
$sContent = str_replace('<?php', '', $sContent);
|
||||||
$sContent = str_replace( '<?', '', $sContent );
|
$sContent = str_replace('<?', '', $sContent);
|
||||||
$sContent = str_replace( '?>', '', $sContent );
|
$sContent = str_replace('?>', '', $sContent);
|
||||||
$sContent = str_replace( 'define', '', $sContent );
|
$sContent = str_replace('define', '', $sContent);
|
||||||
$sContent = str_replace( "('", '$', $sContent );
|
$sContent = str_replace("('", '$', $sContent);
|
||||||
$sContent = str_replace( "',", '=', $sContent );
|
$sContent = str_replace("',", '=', $sContent);
|
||||||
$sContent = str_replace( ");", ';', $sContent );
|
$sContent = str_replace(");", ';', $sContent);
|
||||||
return $sContent;
|
return $sContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
function processMasterSchemaFile ($sSchemaFile)
|
function processMasterSchemaFile($schemaFile)
|
||||||
{
|
{
|
||||||
global $DB_ADAPTER;
|
global $DB_ADAPTER;
|
||||||
global $DB_HOST;
|
global $DB_HOST;
|
||||||
global $DB_USER;
|
global $DB_USER;
|
||||||
global $DB_PASS;
|
global $DB_PASS;
|
||||||
global $DB_NAME;
|
global $DB_NAME;
|
||||||
global $aUpgradeData;
|
global $upgradeData;
|
||||||
|
|
||||||
//convert newSchema to array
|
//convert newSchema to array
|
||||||
if (isset( $aUpgradeData['aNewSchema'] )) {
|
if (isset($upgradeData['aNewSchema'])) {
|
||||||
$aNewSchema = $aUpgradeData['aNewSchema'];
|
$newSchema = $upgradeData['aNewSchema'];
|
||||||
} else {
|
} else {
|
||||||
$aNewSchema = schemaToArray( $sSchemaFile );
|
$newSchema = schemaToArray($schemaFile);
|
||||||
$aUpgradeData['aNewSchema'] = $aNewSchema;
|
$upgradeData['aNewSchema'] = $newSchema;
|
||||||
}
|
}
|
||||||
$aOldSchema = processSchemaFile();
|
$oldSchema = processSchemaFile();
|
||||||
if (is_null( $aOldSchema )) {
|
if (is_null($oldSchema)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$aChanges = obtainChanges( $aOldSchema, $aNewSchema );
|
$changes = obtainChanges($oldSchema, $newSchema);
|
||||||
|
|
||||||
$oDataBase = new database( $DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME );
|
$database = new database($DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
|
||||||
if (! $oDataBase->isConnected()) {
|
if (!$database->isConnected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$oDataBase->iFetchType = MYSQL_NUM;
|
$database->iFetchType = MYSQLI_NUM;
|
||||||
|
|
||||||
$oDataBase->logQuery( count( $aChanges ) );
|
$database->logQuery(count($changes));
|
||||||
|
|
||||||
foreach ($aChanges['tablesToAdd'] as $sTable => $aColumns) {
|
foreach ($changes['tablesToAdd'] as $table => $columns) {
|
||||||
$oDataBase->executeQuery( $oDataBase->generateCreateTableSQL( $sTable, $aColumns ) );
|
$database->executeQuery($database->generateCreateTableSQL($table, $columns));
|
||||||
if (isset( $aChanges['tablesToAdd'][$sTable]['INDEXES'] )) {
|
if (isset($changes['tablesToAdd'][$table]['INDEXES'])) {
|
||||||
foreach ($aChanges['tablesToAdd'][$sTable]['INDEXES'] as $indexName => $aIndex) {
|
foreach ($changes['tablesToAdd'][$table]['INDEXES'] as $indexName => $attribute) {
|
||||||
$oDataBase->executeQuery( $oDataBase->generateAddKeysSQL( $sTable, $indexName, $aIndex ) );
|
$database->executeQuery($database->generateAddKeysSQL($table, $indexName, $attribute));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($aChanges['tablesToAlter'] as $sTable => $aActions) {
|
foreach ($changes['tablesToAlter'] as $table => $actions) {
|
||||||
foreach ($aActions as $sAction => $aAction) {
|
foreach ($actions as $key => $action) {
|
||||||
foreach ($aAction as $sColumn => $vData) {
|
foreach ($action as $column => $data) {
|
||||||
switch ($sAction) {
|
switch ($key) {
|
||||||
case 'DROP':
|
case 'DROP':
|
||||||
$oDataBase->executeQuery( $oDataBase->generateDropColumnSQL( $sTable, $vData ) );
|
$database->executeQuery($database->generateDropColumnSQL($table, $data));
|
||||||
break;
|
break;
|
||||||
case 'ADD':
|
case 'ADD':
|
||||||
$oDataBase->executeQuery( $oDataBase->generateAddColumnSQL( $sTable, $sColumn, $vData ) );
|
$database->executeQuery($database->generateAddColumnSQL($table, $column, $data));
|
||||||
break;
|
break;
|
||||||
case 'CHANGE':
|
case 'CHANGE':
|
||||||
$oDataBase->executeQuery( $oDataBase->generateChangeColumnSQL( $sTable, $sColumn, $vData ) );
|
$database->executeQuery($database->generateChangeColumnSQL($table, $column, $data));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($aChanges['tablesWithNewIndex'] as $sTable => $aIndexes) {
|
foreach ($changes['tablesWithNewIndex'] as $table => $index) {
|
||||||
foreach ($aIndexes as $sIndexName => $aIndexFields) {
|
foreach ($index as $indexName => $indexFields) {
|
||||||
$oDataBase->executeQuery( $oDataBase->generateAddKeysSQL( $sTable, $sIndexName, $aIndexFields ) );
|
$database->executeQuery($database->generateAddKeysSQL($table, $indexName, $indexFields));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($aChanges['tablesToAlterIndex'] as $sTable => $aIndexes) {
|
foreach ($changes['tablesToAlterIndex'] as $table => $index) {
|
||||||
foreach ($aIndexes as $sIndexName => $aIndexFields) {
|
foreach ($index as $indexName => $indexFields) {
|
||||||
$oDataBase->executeQuery( $oDataBase->generateDropKeySQL( $sTable, $sIndexName ) );
|
$database->executeQuery($database->generateDropKeySQL($table, $indexName));
|
||||||
$oDataBase->executeQuery( $oDataBase->generateAddKeysSQL( $sTable, $sIndexName, $aIndexFields ) );
|
$database->executeQuery($database->generateAddKeysSQL($table, $indexName, $indexFields));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$oDataBase->close();
|
$database->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
function processSchemaFile ()
|
function processSchemaFile()
|
||||||
{
|
{
|
||||||
global $DB_ADAPTER;
|
global $DB_ADAPTER;
|
||||||
global $DB_HOST;
|
global $DB_HOST;
|
||||||
@@ -162,232 +141,210 @@ function processSchemaFile ()
|
|||||||
global $DB_NAME;
|
global $DB_NAME;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$oldSchema = [];
|
||||||
|
$database = new database($DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
|
||||||
|
|
||||||
|
if (!$database->isConnected()) {
|
||||||
$aOldSchema = array ();
|
$database->logQuery(G::LoadTranslation('ID_DOES_NOT_EXIST_AVAILABLE_CONNECTION'));
|
||||||
$oDataBase = new database( $DB_ADAPTER, $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME );
|
|
||||||
|
|
||||||
if (! $oDataBase->isConnected()) {
|
|
||||||
$oDataBase->logQuery( G::LoadTranslation('ID_DOES_NOT_EXIST_AVAILABLE_CONNECTION') );
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$oDataBase->iFetchType = MYSQL_NUM;
|
$database->iFetchType = MYSQLI_NUM;
|
||||||
$oDataset1 = $oDataBase->executeQuery( $oDataBase->generateShowTablesSQL() );
|
$result = $database->executeQuery($database->generateShowTablesSQL());
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$oDataBase->logQuery( $e->getmessage() );
|
$database->logQuery($e->getmessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//going thru all tables in current WF_ database
|
//going thru all tables in current WF_ database
|
||||||
while ($aRow1 = $oDataBase->getRegistry( $oDataset1 )) {
|
foreach ($result as $table) {
|
||||||
$aPrimaryKeys = array ();
|
$table = strtoupper($table);
|
||||||
$sTable = strtoupper( $aRow1[0] );
|
|
||||||
|
|
||||||
//get description of each table, ( column and primary keys )
|
//get description of each table, ( column and primary keys )
|
||||||
//$oDataset2 = $oDataBase->executeQuery( $oDataBase->generateDescTableSQL($aRow1[0]) );
|
$database->iFetchType = MYSQLI_ASSOC;
|
||||||
$oDataset2 = $oDataBase->executeQuery( $oDataBase->generateDescTableSQL( $sTable ) );
|
$description = $database->executeQuery($database->generateDescTableSQL($table));
|
||||||
$aOldSchema[$sTable] = array ();
|
$oldSchema[$table] = [];
|
||||||
$oDataBase->iFetchType = MYSQL_ASSOC;
|
foreach ($description as $field) {
|
||||||
while ($aRow2 = $oDataBase->getRegistry( $oDataset2 )) {
|
$oldSchema[$table][$field['Field']]['Field'] = $field['Field'];
|
||||||
$aOldSchema[$sTable][$aRow2['Field']]['Field'] = $aRow2['Field'];
|
$oldSchema[$table][$field['Field']]['Type'] = $field['Type'];
|
||||||
$aOldSchema[$sTable][$aRow2['Field']]['Type'] = $aRow2['Type'];
|
$oldSchema[$table][$field['Field']]['Null'] = $field['Null'];
|
||||||
$aOldSchema[$sTable][$aRow2['Field']]['Null'] = $aRow2['Null'];
|
$oldSchema[$table][$field['Field']]['Default'] = $field['Default'];
|
||||||
$aOldSchema[$sTable][$aRow2['Field']]['Default'] = $aRow2['Default'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//get indexes of each table SHOW INDEX FROM `ADDITIONAL_TABLES`; -- WHERE Key_name <> 'PRIMARY'
|
//get indexes of each table SHOW INDEX FROM `ADDITIONAL_TABLES`; -- WHERE Key_name <> 'PRIMARY'
|
||||||
$oDataset2 = $oDataBase->executeQuery( $oDataBase->generateTableIndexSQL( $aRow1[0] ) );
|
$description = $database->executeQuery($database->generateTableIndexSQL($table));
|
||||||
$oDataBase->iFetchType = MYSQL_ASSOC;
|
foreach ($description as $field) {
|
||||||
while ($aRow2 = $oDataBase->getRegistry( $oDataset2 )) {
|
if (!isset($oldSchema[$table]['INDEXES'])) {
|
||||||
if (! isset( $aOldSchema[$sTable]['INDEXES'] )) {
|
$oldSchema[$table]['INDEXES'] = [];
|
||||||
$aOldSchema[$sTable]['INDEXES'] = array ();
|
|
||||||
}
|
}
|
||||||
if (! isset( $aOldSchema[$sTable]['INDEXES'][$aRow2['Key_name']] )) {
|
if (!isset($oldSchema[$table]['INDEXES'][$field['Key_name']])) {
|
||||||
$aOldSchema[$sTable]['INDEXES'][$aRow2['Key_name']] = array ();
|
$oldSchema[$table]['INDEXES'][$field['Key_name']] = [];
|
||||||
}
|
}
|
||||||
$aOldSchema[$sTable]['INDEXES'][$aRow2['Key_name']][] = $aRow2['Column_name'];
|
$oldSchema[$table]['INDEXES'][$field['Key_name']][] = $field['Column_name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$oDataBase->iFetchType = MYSQL_NUM; //this line is neccesary because the next fetch needs to be with MYSQL_NUM
|
|
||||||
}
|
}
|
||||||
//finally return the array with old schema obtained from the Database
|
//finally return the array with old schema obtained from the Database
|
||||||
if (count( $aOldSchema ) == 0)
|
if (count($oldSchema) === 0) {
|
||||||
$aOldSchema = null;
|
$oldSchema = null;
|
||||||
return $aOldSchema;
|
}
|
||||||
|
return $oldSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
//process the schema file in the patch file, and obtain an array
|
//process the schema file in the patch file, and obtain an array
|
||||||
function schemaToArray ($sSchemaFile)
|
function schemaToArray($schemaFile)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$aSchema = array ();
|
$schema = [];
|
||||||
$oXml = new DomDocument();
|
$xml = new DomDocument();
|
||||||
$oXml->load( $sSchemaFile );
|
$xml->load($schemaFile);
|
||||||
$aTables = $oXml->getElementsByTagName( 'table' );
|
$tables = $xml->getElementsByTagName('table');
|
||||||
foreach ($aTables as $oTable) {
|
foreach ($tables as $table) {
|
||||||
$aPrimaryKeys = array ();
|
$primaryKeys = [];
|
||||||
$sTableName = $oTable->getAttribute( 'name' );
|
$tableName = $table->getAttribute('name');
|
||||||
$aSchema[$sTableName] = array ();
|
$schema[$tableName] = [];
|
||||||
$aColumns = $oTable->getElementsByTagName( 'column' );
|
$columns = $table->getElementsByTagName('column');
|
||||||
foreach ($aColumns as $oColumn) {
|
foreach ($columns as $column) {
|
||||||
$sColumName = $oColumn->getAttribute( 'name' );
|
$columnName = $column->getAttribute('name');
|
||||||
$aSchema[$sTableName][$sColumName] = array ();
|
$schema[$tableName][$columnName] = [];
|
||||||
$aVendors = $oColumn->getElementsByTagName( 'vendor' );
|
$vendors = $column->getElementsByTagName('vendor');
|
||||||
foreach ($aVendors as $oVendor) {
|
foreach ($vendors as $vendor) {
|
||||||
if ($oVendor->getAttribute( 'type' ) == DB_ADAPTER) {
|
if ($vendor->getAttribute('type') == config('connections.driver')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$aParameters = $oColumn->getElementsByTagName( 'parameter' );
|
$parameters = $column->getElementsByTagName('parameter');
|
||||||
foreach ($aParameters as $oParameter) {
|
foreach ($parameters as $oParameter) {
|
||||||
$parameterName = ucwords( $oParameter->getAttribute( 'name' ) );
|
$parameterName = ucwords($oParameter->getAttribute('name'));
|
||||||
if ($parameterName == 'Key' && strtoupper( $oParameter->getAttribute( 'value' ) ) == 'PRI') {
|
if ($parameterName == 'Key' && strtoupper($oParameter->getAttribute('value')) == 'PRI') {
|
||||||
$aPrimaryKeys[] = $oColumn->getAttribute( 'name' );
|
$primaryKeys[] = $column->getAttribute('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array( $parameterName, array ('Field','Type','Null','Default'
|
if (in_array($parameterName, ['Field', 'Type', 'Null', 'Default'])) {
|
||||||
) )) {
|
$schema[$tableName][$columnName][$parameterName] = $oParameter->getAttribute('value');
|
||||||
$aSchema[$sTableName][$sColumName][$parameterName] = $oParameter->getAttribute( 'value' );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array( $aPrimaryKeys ) && count( $aPrimaryKeys ) > 0) {
|
if (is_array($primaryKeys) && count($primaryKeys) > 0) {
|
||||||
$aSchema[$sTableName]['INDEXES']['PRIMARY'] = $aPrimaryKeys;
|
$schema[$tableName]['INDEXES']['PRIMARY'] = $primaryKeys;
|
||||||
}
|
}
|
||||||
$aIndexes = $oTable->getElementsByTagName( 'index' );
|
$index = $table->getElementsByTagName('index');
|
||||||
foreach ($aIndexes as $oIndex) {
|
foreach ($index as $fieldIndex) {
|
||||||
$aIndex = array ();
|
$attribute = [];
|
||||||
$aIndexesColumns = $oIndex->getElementsByTagName( 'index-column' );
|
$aIndexesColumns = $fieldIndex->getElementsByTagName('index-column');
|
||||||
foreach ($aIndexesColumns as $oIndexColumn) {
|
foreach ($aIndexesColumns as $oIndexColumn) {
|
||||||
$aIndex[] = $oIndexColumn->getAttribute( 'name' );
|
$attribute[] = $oIndexColumn->getAttribute('name');
|
||||||
}
|
}
|
||||||
$aSchema[$sTableName]['INDEXES'][$oIndex->getAttribute( 'name' )] = $aIndex;
|
$schema[$tableName]['INDEXES'][$fieldIndex->getAttribute('name')] = $attribute;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $aSchema;
|
return $schema;
|
||||||
} catch (Exception $oError) {
|
} catch (Exception $oError) {
|
||||||
throw $oError;
|
throw $oError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function obtainChanges ($aOldSchema, $aNewSchema)
|
function obtainChanges($oldSchema, $newSchema)
|
||||||
{
|
{
|
||||||
//$aChanges = array('tablesToDelete' => array(), 'tablesToAdd' => array(), 'tablesToAlter' => array());
|
|
||||||
//Tables to delete, but this is disabled
|
|
||||||
//foreach ($aOldSchema as $sTableName => $aColumns) {
|
|
||||||
// if ( !isset($aNewSchema[$sTableName])) {
|
|
||||||
// if (!in_array($sTableName, array('KT_APPLICATION', 'KT_DOCUMENT', 'KT_PROCESS'))) {
|
|
||||||
// $aChanges['tablesToDelete'][] = $sTableName;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
$changes = ['tablesToAdd' => [], 'tablesToAlter' => [], 'tablesWithNewIndex' => [], 'tablesToAlterIndex' => []];
|
||||||
$aChanges = array ('tablesToAdd' => array (),'tablesToAlter' => array (),'tablesWithNewIndex' => array (),'tablesToAlterIndex' => array ()
|
|
||||||
);
|
|
||||||
|
|
||||||
//new tables to create and alter
|
//new tables to create and alter
|
||||||
foreach ($aNewSchema as $sTableName => $aColumns) {
|
foreach ($newSchema as $tableName => $columns) {
|
||||||
if (! isset( $aOldSchema[$sTableName] )) {
|
if (!isset($oldSchema[$tableName])) {
|
||||||
$aChanges['tablesToAdd'][$sTableName] = $aColumns;
|
$changes['tablesToAdd'][$tableName] = $columns;
|
||||||
} else {
|
} else {
|
||||||
//drop old columns
|
//drop old columns
|
||||||
foreach ($aOldSchema[$sTableName] as $sColumName => $aParameters) {
|
foreach ($oldSchema[$tableName] as $columnName => $parameters) {
|
||||||
if (! isset( $aNewSchema[$sTableName][$sColumName] )) {
|
if (!isset($newSchema[$tableName][$columnName])) {
|
||||||
if (! isset( $aChanges['tablesToAlter'][$sTableName] )) {
|
if (!isset($changes['tablesToAlter'][$tableName])) {
|
||||||
$aChanges['tablesToAlter'][$sTableName] = array ('DROP' => array (),'ADD' => array (),'CHANGE' => array ()
|
$changes['tablesToAlter'][$tableName] = ['DROP' => [], 'ADD' => [], 'CHANGE' => []];
|
||||||
);
|
|
||||||
}
|
}
|
||||||
$aChanges['tablesToAlter'][$sTableName]['DROP'][$sColumName] = $sColumName;
|
$changes['tablesToAlter'][$tableName]['DROP'][$columnName] = $columnName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//create new columns
|
//create new columns
|
||||||
//foreach ($aNewSchema[$sTableName] as $sColumName => $aParameters) {
|
foreach ($columns as $columnName => $parameters) {
|
||||||
foreach ($aColumns as $sColumName => $aParameters) {
|
if ($columnName != 'INDEXES') {
|
||||||
if ($sColumName != 'INDEXES') {
|
if (!isset($oldSchema[$tableName][$columnName])) { //this column doesnt exist in oldschema
|
||||||
if (! isset( $aOldSchema[$sTableName][$sColumName] )) { //this column doesnt exist in oldschema
|
if (!isset($changes['tablesToAlter'][$tableName])) {
|
||||||
if (! isset( $aChanges['tablesToAlter'][$sTableName] )) {
|
$changes['tablesToAlter'][$tableName] = ['DROP' => [], 'ADD' => [], 'CHANGE' => []];
|
||||||
$aChanges['tablesToAlter'][$sTableName] = array ('DROP' => array (),'ADD' => array (),'CHANGE' => array ()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
$aChanges['tablesToAlter'][$sTableName]['ADD'][$sColumName] = $aParameters;
|
$changes['tablesToAlter'][$tableName]['ADD'][$columnName] = $parameters;
|
||||||
} else { //the column exists
|
} else { //the column exists
|
||||||
$newField = $aNewSchema[$sTableName][$sColumName];
|
$newField = $newSchema[$tableName][$columnName];
|
||||||
$oldField = $aOldSchema[$sTableName][$sColumName];
|
$oldField = $oldSchema[$tableName][$columnName];
|
||||||
//both are null, no change is required
|
//both are null, no change is required
|
||||||
if (! isset( $newField['Default'] ) && ! isset( $oldField['Default'] ))
|
if (!isset($newField['Default']) && !isset($oldField['Default']))
|
||||||
$changeDefaultAttr = false;
|
$changeDefaultAttr = false;
|
||||||
//one of them is null, change IS required
|
//one of them is null, change IS required
|
||||||
if (! isset( $newField['Default'] ) && isset( $oldField['Default'] ) && $oldField['Default'] != '')
|
if (!isset($newField['Default']) && isset($oldField['Default']) && $oldField['Default'] != '')
|
||||||
$changeDefaultAttr = true;
|
$changeDefaultAttr = true;
|
||||||
if (isset( $newField['Default'] ) && ! isset( $oldField['Default'] ))
|
if (isset($newField['Default']) && !isset($oldField['Default']))
|
||||||
$changeDefaultAttr = true;
|
$changeDefaultAttr = true;
|
||||||
//both are defined and they are different.
|
//both are defined and they are different.
|
||||||
if (isset( $newField['Default'] ) && isset( $oldField['Default'] )) {
|
if (isset($newField['Default']) && isset($oldField['Default'])) {
|
||||||
if ($newField['Default'] != $oldField['Default'])
|
$changeDefaultAttr = false;
|
||||||
|
if ($newField['Default'] != $oldField['Default']) {
|
||||||
$changeDefaultAttr = true;
|
$changeDefaultAttr = true;
|
||||||
else
|
}
|
||||||
$changeDefaultAttr = false;
|
|
||||||
}
|
}
|
||||||
//special cases
|
//special cases
|
||||||
// BLOB and TEXT columns cannot have DEFAULT values. http://dev.mysql.com/doc/refman/5.0/en/blob.html
|
// BLOB and TEXT columns cannot have DEFAULT values. http://dev.mysql.com/doc/refman/5.0/en/blob.html
|
||||||
if (in_array( strtolower( $newField['Type'] ), array ('text','mediumtext'
|
if (in_array(strtolower($newField['Type']), ['text', 'mediumtext']))
|
||||||
) ))
|
|
||||||
$changeDefaultAttr = false;
|
$changeDefaultAttr = false;
|
||||||
|
|
||||||
//#1067 - Invalid default value for datetime field
|
//#1067 - Invalid default value for datetime field
|
||||||
if (in_array( $newField['Type'], array ('datetime'
|
if (in_array($newField['Type'], ['datetime']) && isset($newField['Default']) && $newField['Default'] == '') {
|
||||||
) ) && isset( $newField['Default'] ) && $newField['Default'] == '')
|
|
||||||
$changeDefaultAttr = false;
|
$changeDefaultAttr = false;
|
||||||
|
}
|
||||||
|
|
||||||
//#1067 - Invalid default value for int field
|
//#1067 - Invalid default value for int field
|
||||||
if (substr( $newField['Type'], 0, 3 ) && isset( $newField['Default'] ) && $newField['Default'] == '')
|
if (substr($newField['Type'], 0, 3) && isset($newField['Default']) && $newField['Default'] == '') {
|
||||||
$changeDefaultAttr = false;
|
$changeDefaultAttr = false;
|
||||||
|
}
|
||||||
|
|
||||||
//if any difference exists, then insert the difference in aChanges
|
//if any difference exists, then insert the difference in aChanges
|
||||||
if ($newField['Field'] != $oldField['Field'] || $newField['Type'] != $oldField['Type'] || $newField['Null'] != $oldField['Null'] || $changeDefaultAttr) {
|
if ($newField['Field'] != $oldField['Field'] || $newField['Type'] != $oldField['Type'] || $newField['Null'] != $oldField['Null'] || $changeDefaultAttr) {
|
||||||
if (! isset( $aChanges['tablesToAlter'][$sTableName] )) {
|
if (!isset($changes['tablesToAlter'][$tableName])) {
|
||||||
$aChanges['tablesToAlter'][$sTableName] = array ('DROP' => array (),'ADD' => array (),'CHANGE' => array ()
|
$changes['tablesToAlter'][$tableName] = ['DROP' => [], 'ADD' => [], 'CHANGE' => []];
|
||||||
);
|
}
|
||||||
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Field'] = $newField['Field'];
|
||||||
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Type'] = $newField['Type'];
|
||||||
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Null'] = $newField['Null'];
|
||||||
|
if (isset($newField['Default'])) {
|
||||||
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Default'] = $newField['Default'];
|
||||||
|
} else {
|
||||||
|
$changes['tablesToAlter'][$tableName]['CHANGE'][$columnName]['Default'] = null;
|
||||||
}
|
}
|
||||||
$aChanges['tablesToAlter'][$sTableName]['CHANGE'][$sColumName]['Field'] = $newField['Field'];
|
|
||||||
$aChanges['tablesToAlter'][$sTableName]['CHANGE'][$sColumName]['Type'] = $newField['Type'];
|
|
||||||
$aChanges['tablesToAlter'][$sTableName]['CHANGE'][$sColumName]['Null'] = $newField['Null'];
|
|
||||||
if (isset( $newField['Default'] ))
|
|
||||||
$aChanges['tablesToAlter'][$sTableName]['CHANGE'][$sColumName]['Default'] = $newField['Default'];
|
|
||||||
else
|
|
||||||
$aChanges['tablesToAlter'][$sTableName]['CHANGE'][$sColumName]['Default'] = null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //only columns, no the indexes column
|
} //only columns, no the indexes column
|
||||||
} //foreach $aColumns
|
} //foreach $columns
|
||||||
|
|
||||||
|
|
||||||
//now check the indexes of table
|
//now check the indexes of table
|
||||||
if (isset( $aNewSchema[$sTableName]['INDEXES'] )) {
|
if (isset($newSchema[$tableName]['INDEXES'])) {
|
||||||
foreach ($aNewSchema[$sTableName]['INDEXES'] as $indexName => $indexFields) {
|
foreach ($newSchema[$tableName]['INDEXES'] as $indexName => $indexFields) {
|
||||||
if (! isset( $aOldSchema[$sTableName]['INDEXES'][$indexName] )) {
|
if (!isset($oldSchema[$tableName]['INDEXES'][$indexName])) {
|
||||||
if (! isset( $aChanges['tablesWithNewIndex'][$sTableName] )) {
|
if (!isset($changes['tablesWithNewIndex'][$tableName])) {
|
||||||
$aChanges['tablesWithNewIndex'][$sTableName] = array ();
|
$changes['tablesWithNewIndex'][$tableName] = [];
|
||||||
}
|
}
|
||||||
$aChanges['tablesWithNewIndex'][$sTableName][$indexName] = $indexFields;
|
$changes['tablesWithNewIndex'][$tableName][$indexName] = $indexFields;
|
||||||
} else {
|
} else {
|
||||||
if ($aOldSchema[$sTableName]['INDEXES'][$indexName] != $indexFields) {
|
if ($oldSchema[$tableName]['INDEXES'][$indexName] != $indexFields) {
|
||||||
if (! isset( $aChanges['tablesToAlterIndex'][$sTableName] )) {
|
if (!isset($changes['tablesToAlterIndex'][$tableName])) {
|
||||||
$aChanges['tablesToAlterIndex'][$sTableName] = array ();
|
$changes['tablesToAlterIndex'][$tableName] = [];
|
||||||
}
|
}
|
||||||
$aChanges['tablesToAlterIndex'][$sTableName][$indexName] = $indexFields;
|
$changes['tablesToAlterIndex'][$tableName][$indexName] = $indexFields;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //for-else table exists
|
} //for-else table exists
|
||||||
} //for new schema
|
} //for new schema
|
||||||
return $aChanges;
|
return $changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ namespace ProcessMaker\Core;
|
|||||||
|
|
||||||
use AppCacheView;
|
use AppCacheView;
|
||||||
use Archive_Tar;
|
use Archive_Tar;
|
||||||
|
use Bootstrap;
|
||||||
use Configuration;
|
use Configuration;
|
||||||
use Exception;
|
use Exception;
|
||||||
use G;
|
use G;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use InstallerModule;
|
||||||
|
use ProcessMaker\Util\Common;
|
||||||
|
|
||||||
class Installer
|
class Installer
|
||||||
{
|
{
|
||||||
@@ -16,6 +21,9 @@ class Installer
|
|||||||
public $report = [];
|
public $report = [];
|
||||||
private $connection_database;
|
private $connection_database;
|
||||||
|
|
||||||
|
const CONNECTION_INSTALL = 'install';
|
||||||
|
const CONNECTION_TEST_INSTALL = 'testInstall';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* construct of insert
|
* construct of insert
|
||||||
*
|
*
|
||||||
@@ -31,18 +39,41 @@ class Installer
|
|||||||
*
|
*
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @param boolean $confirmed
|
* @param boolean $confirmed
|
||||||
* @return void
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function create_site($config = array(), $confirmed = false)
|
public function create_site($config = [], $confirmed = false)
|
||||||
{
|
{
|
||||||
$this->options = G::array_concat(array('isset' => false, 'password' => G::generate_password(15), 'path_data' => @PATH_DATA, 'path_compiled' => @PATH_C, 'name' => $config['name'], 'database' => array(), 'admin' => array('username' => 'admin', 'password' => 'admin'
|
$this->options = G::array_concat([
|
||||||
), 'advanced' => array('ao_db_wf' => 'wf_' . $config['name'], 'ao_db_rb' => 'rb_' . $config['name'], 'ao_db_rp' => 'rp_' . $config['name'], 'ao_db_drop' => false
|
'isset' => false,
|
||||||
)
|
'password' => G::generate_password(15),
|
||||||
), $config);
|
'path_data' => @PATH_DATA,
|
||||||
$a = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
|
'path_compiled' => @PATH_C,
|
||||||
$this->options['database'] = G::array_concat(array('username' => @$a[1], 'password' => @$a[2], 'hostname' => @$a[0]
|
'name' => $config['name'],
|
||||||
), $this->options['database']);
|
'database' => [],
|
||||||
return ($confirmed === true) ? $this->make_site() : $this->create_site_test();
|
'admin' => ['username' => 'admin', 'password' => 'admin'],
|
||||||
|
'advanced' => [
|
||||||
|
'ao_db_wf' => 'wf_' . $config['name'],
|
||||||
|
'ao_db_rb' => 'rb_' . $config['name'],
|
||||||
|
'ao_db_rp' => 'rp_' . $config['name'],
|
||||||
|
'ao_db_drop' => false
|
||||||
|
]
|
||||||
|
], $config);
|
||||||
|
$configuration = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
|
||||||
|
|
||||||
|
$host = explode(':', $configuration[0]);
|
||||||
|
if (count($host) < 2) {
|
||||||
|
$host[1] = 3306;
|
||||||
|
}
|
||||||
|
$configuration[0] = $host[0];
|
||||||
|
|
||||||
|
$this->options['database'] = G::array_concat([
|
||||||
|
'username' => @$configuration[1],
|
||||||
|
'password' => @$configuration[2],
|
||||||
|
'hostname' => @$configuration[0],
|
||||||
|
'port' => $host[1]
|
||||||
|
], $this->options['database']);
|
||||||
|
|
||||||
|
return $confirmed ? $this->make_site() : $this->create_site_test();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,30 +98,44 @@ class Installer
|
|||||||
/**
|
/**
|
||||||
* create_site_test
|
* create_site_test
|
||||||
*
|
*
|
||||||
* @return void
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function create_site_test()
|
private function create_site_test()
|
||||||
{
|
{
|
||||||
$name = (preg_match('/^[\w]+$/i', trim($this->options['name']))) ? true : false;
|
$name = preg_match('/^[\w]+$/i', trim($this->options['name'])) ? true : false;
|
||||||
$result = array('path_data' => $this->is_dir_writable($this->options['path_data']), 'path_compiled' => $this->is_dir_writable($this->options['path_compiled']), 'database' => $this->check_connection(), 'access_level' => $this->cc_status, 'isset' => ($this->options['isset'] == true) ? $this->isset_site($this->options['name']) : false, 'microtime' => microtime(), 'workspace' => $this->options['name'], 'name' => array('status' => $name, 'message' => ($name) ? 'PASSED' : 'Workspace name invalid'
|
$result = [
|
||||||
), 'admin' => array('username' => (preg_match('/^[\w@\.-]+$/i', trim($this->options['admin']['username']))) ? true : false, 'password' => ((trim($this->options['admin']['password']) == '') ? false : true)
|
'path_data' => $this->is_dir_writable($this->options['path_data']),
|
||||||
)
|
'path_compiled' => $this->is_dir_writable($this->options['path_compiled']),
|
||||||
);
|
'database' => $this->check_connection(self::CONNECTION_TEST_INSTALL),
|
||||||
$result['name']['message'] = ($result['isset']) ? 'Workspace already exist' : $result['name']['message'];
|
'access_level' => $this->cc_status,
|
||||||
$result['name']['status'] = ($result['isset']) ? false : $result['name']['status'];
|
'isset' => $this->options['isset'] === true ? $this->isset_site($this->options['name']) : false,
|
||||||
return array('created' => G::var_compare(
|
'microtime' => microtime(),
|
||||||
true,
|
'workspace' => $this->options['name'],
|
||||||
$result['path_data'],
|
'name' => [
|
||||||
$result['database']['connection'],
|
'status' => $name,
|
||||||
$result['name']['status'],
|
'message' => $name ? 'PASSED' : 'Workspace name invalid'
|
||||||
$result['database']['version'],
|
],
|
||||||
$result['database']['ao']['ao_db_wf']['status'],
|
'admin' => [
|
||||||
$result['admin']['username'],
|
'username' => preg_match('/^[\w@\.-]+$/i', trim($this->options['admin']['username'])) ? true : false,
|
||||||
(($result['isset']) ? false : true),
|
'password' => empty(trim($this->options['admin']['password'])) ? false : true
|
||||||
$result['admin']['password']
|
]
|
||||||
),
|
];
|
||||||
|
$result['name']['message'] = $result['isset'] ? 'Workspace already exist' : $result['name']['message'];
|
||||||
|
$result['name']['status'] = $result['isset'] ? false : $result['name']['status'];
|
||||||
|
return [
|
||||||
|
'created' => G::var_compare(
|
||||||
|
true,
|
||||||
|
$result['path_data'],
|
||||||
|
$result['database']['connection'],
|
||||||
|
$result['name']['status'],
|
||||||
|
$result['database']['version'],
|
||||||
|
$result['database']['ao']['ao_db_wf']['status'],
|
||||||
|
$result['admin']['username'],
|
||||||
|
$result['isset'] ? false : true,
|
||||||
|
$result['admin']['password']
|
||||||
|
),
|
||||||
'result' => $result
|
'result' => $result
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,9 +147,10 @@ class Installer
|
|||||||
{
|
{
|
||||||
$test = $this->create_site_test();
|
$test = $this->create_site_test();
|
||||||
|
|
||||||
if ($test["created"] == true || $this->options["advanced"]["ao_db_drop"] == true) {
|
if ($test["created"] === true || $this->options["advanced"]["ao_db_drop"] === true) {
|
||||||
/* Check if the hostname is local (localhost or 127.0.0.1) */
|
/* Check if the hostname is local (localhost or 127.0.0.1) */
|
||||||
$islocal = (strcmp(substr($this->options['database']['hostname'], 0, strlen('localhost')), 'localhost') === 0) || (strcmp(substr($this->options['database']['hostname'], 0, strlen('127.0.0.1')), '127.0.0.1') === 0);
|
$islocal = (strcmp(substr($this->options['database']['hostname'], 0, strlen('localhost')), 'localhost') === 0) ||
|
||||||
|
(strcmp(substr($this->options['database']['hostname'], 0, strlen('127.0.0.1')), '127.0.0.1') === 0);
|
||||||
|
|
||||||
$this->wf_site_name = $wf = $this->options['advanced']['ao_db_wf'];
|
$this->wf_site_name = $wf = $this->options['advanced']['ao_db_wf'];
|
||||||
$this->wf_user_db = isset($this->options['advanced']['ao_user_wf']) ? $this->options['advanced']['ao_user_wf'] : uniqid('wf_');
|
$this->wf_user_db = isset($this->options['advanced']['ao_user_wf']) ? $this->options['advanced']['ao_user_wf'] : uniqid('wf_');
|
||||||
@@ -118,36 +164,39 @@ class Installer
|
|||||||
if ($this->options['advanced']['ao_db_drop'] === true) {
|
if ($this->options['advanced']['ao_db_drop'] === true) {
|
||||||
//Delete workspace directory if exists
|
//Delete workspace directory if exists
|
||||||
//Drop databases
|
//Drop databases
|
||||||
$this->run_query("DROP DATABASE IF EXISTS " . $wf, "Drop database $wf");
|
$this->run_query('DROP DATABASE IF EXISTS ' . $wf, 'Drop database $wf', self::CONNECTION_TEST_INSTALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->run_query("CREATE DATABASE IF NOT EXISTS " . $wf . " DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci", "Create database $wf");
|
$this->run_query('CREATE DATABASE IF NOT EXISTS ' . $wf . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci', "Create database $wf", self::CONNECTION_TEST_INSTALL);
|
||||||
|
|
||||||
|
|
||||||
if ($this->cc_status == 1) {
|
if ($this->cc_status == 1) {
|
||||||
$host = ($islocal) ? "localhost" : "%";
|
$host = ($islocal) ? "localhost" : "%";
|
||||||
$this->run_query("GRANT ALL PRIVILEGES ON `$wf`.* TO {$this->wf_user_db}@'$host' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION", "Grant privileges for user {$this->wf_user_db} on database $wf");
|
$this->run_query("GRANT ALL PRIVILEGES ON `$wf`.* TO {$this->wf_user_db}@'$host' IDENTIFIED BY '{$this->options['password']}' WITH GRANT OPTION", "Grant privileges for user {$this->wf_user_db} on database $wf", self::CONNECTION_TEST_INSTALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Dump schema workflow && data */
|
/* Dump schema workflow && data */
|
||||||
|
|
||||||
$this->log("Import database schema:\n");
|
$this->log("Import database schema:\n");
|
||||||
$myPortA = explode(":", $this->options['database']['hostname']);
|
|
||||||
if (count($myPortA) < 2) {
|
|
||||||
$myPortA[1] = "3306";
|
|
||||||
}
|
|
||||||
$myPort = $myPortA[1];
|
|
||||||
$this->options['database']['hostname'] = $myPortA[0];
|
|
||||||
|
|
||||||
mysqli_select_db($this->connection_database, $wf);
|
InstallerModule::setNewConnection(
|
||||||
|
self::CONNECTION_INSTALL,
|
||||||
|
$this->options['database']['hostname'],
|
||||||
|
$this->options['database']['username'],
|
||||||
|
$this->options['database']['password'],
|
||||||
|
$this->wf_site_name,
|
||||||
|
$this->options['database']['port']);
|
||||||
|
|
||||||
$pws = PATH_WORKFLOW_MYSQL_DATA . $schema;
|
$pws = PATH_WORKFLOW_MYSQL_DATA . $schema;
|
||||||
$qws = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA . $schema, $this->connection_database);
|
$qws = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA . $schema);
|
||||||
$this->log($qws, isset($qws['errors']));
|
$this->log($qws, isset($qws['errors']));
|
||||||
$qwv = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA . $values, $this->connection_database);
|
$qwv = $this->query_sql_file(PATH_WORKFLOW_MYSQL_DATA . $values);
|
||||||
$this->log($qwv, isset($qwv['errors']));
|
$this->log($qwv, isset($qwv['errors']));
|
||||||
|
|
||||||
$http = (G::is_https() == true) ? 'https' : 'http';
|
$http = G::is_https() ? 'https' : 'http';
|
||||||
$lang = defined('SYS_LANG') ? SYS_LANG : 'en';
|
$lang = defined('SYS_LANG') ? SYS_LANG : 'en';
|
||||||
$host = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '');
|
$host = $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] !== '80' ? ':' . $_SERVER['SERVER_PORT'] : '');
|
||||||
$workspace = $this->options['name'];
|
$workspace = $this->options['name'];
|
||||||
|
|
||||||
$endpoint = sprintf(
|
$endpoint = sprintf(
|
||||||
@@ -159,33 +208,37 @@ class Installer
|
|||||||
SYS_SKIN
|
SYS_SKIN
|
||||||
);
|
);
|
||||||
|
|
||||||
// inserting the outh_client
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
$query = ("INSERT INTO OAUTH_CLIENTS (CLIENT_ID,CLIENT_SECRET,CLIENT_NAME,CLIENT_DESCRIPTION,CLIENT_WEBSITE,REDIRECT_URI,USR_UID ) VALUES
|
->table('OAUTH_CLIENTS')
|
||||||
('x-pm-local-client','179ad45c6ce2cb97cf1029e212046e81','PM Web Designer','ProcessMaker Web Designer App','www.processmaker.com','" . $endpoint . "','00000000000000000000000000000001' )");
|
->insert([
|
||||||
$this->run_query($query);
|
'CLIENT_ID' => 'x-pm-local-client',
|
||||||
|
'CLIENT_SECRET' => '179ad45c6ce2cb97cf1029e212046e81',
|
||||||
|
'CLIENT_NAME' => 'PM Web Designer',
|
||||||
|
'CLIENT_DESCRIPTION' => 'ProcessMaker Web Designer App',
|
||||||
|
'CLIENT_WEBSITE' => 'www.processmaker.com',
|
||||||
|
'REDIRECT_URI' => $endpoint,
|
||||||
|
'USR_UID' => '00000000000000000000000000000001'
|
||||||
|
]);
|
||||||
|
|
||||||
/* Dump schema rbac && data */
|
/* Dump schema rbac && data */
|
||||||
$pws = PATH_RBAC_MYSQL_DATA . $schema;
|
$pws = PATH_RBAC_MYSQL_DATA . $schema;
|
||||||
mysqli_select_db($this->connection_database, $rb);
|
$qrs = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $schema);
|
||||||
$qrs = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $schema, $this->connection_database);
|
|
||||||
$this->log($qrs, isset($qrs['errors']));
|
$this->log($qrs, isset($qrs['errors']));
|
||||||
$qrv = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $values, $this->connection_database);
|
$qrv = $this->query_sql_file(PATH_RBAC_MYSQL_DATA . $values);
|
||||||
$this->log($qrv, isset($qrv['errors']));
|
$this->log($qrv, isset($qrv['errors']));
|
||||||
|
|
||||||
mysqli_select_db($this->connection_database, $wf);
|
|
||||||
|
|
||||||
require_once("propel/Propel.php");
|
require_once("propel/Propel.php");
|
||||||
require_once('classes/model/AppCacheView.php');
|
require_once('classes/model/AppCacheView.php');
|
||||||
|
|
||||||
$appCache = new AppCacheView();
|
$appCache = new AppCacheView();
|
||||||
$appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup/setupSchemas/');
|
$appCache->setPathToAppCacheFiles(PATH_METHODS . 'setup/setupSchemas/');
|
||||||
$triggers = $appCache->getTriggers("en");
|
$triggers = $appCache->getTriggers('en');
|
||||||
$this->log("Create 'cases list cache' triggers");
|
$this->log("Create 'cases list cache' triggers");
|
||||||
foreach ($triggers as $triggerName => $trigger) {
|
foreach ($triggers as $triggerName => $trigger) {
|
||||||
$this->run_query($trigger, "-> Trigger $triggerName");
|
$this->runTrigger($trigger, "-> Trigger $triggerName");
|
||||||
}
|
}
|
||||||
|
|
||||||
$path_site = $this->options['path_data'] . "/sites/" . $this->options['name'] . "/";
|
$path_site = $this->options['path_data'] . '/sites/' . $this->options['name'] . '/';
|
||||||
|
|
||||||
@mkdir($path_site, 0777, true);
|
@mkdir($path_site, 0777, true);
|
||||||
@mkdir($path_site . "files/", 0777, true);
|
@mkdir($path_site . "files/", 0777, true);
|
||||||
@@ -195,8 +248,27 @@ class Installer
|
|||||||
@mkdir($path_site . "xmlForms", 0777, true);
|
@mkdir($path_site . "xmlForms", 0777, true);
|
||||||
|
|
||||||
//Generate the db.php file
|
//Generate the db.php file
|
||||||
|
$hostname = $this->options['database']['hostname'] . ':' . $this->options['database']['port'];
|
||||||
|
$username = $this->cc_status === 1 ? $this->wf_user_db : $this->options['database']['username'];
|
||||||
|
$password = $this->cc_status === 1 ? $this->options['password'] : $this->options['database']['password'];
|
||||||
$db_file = $path_site . 'db.php';
|
$db_file = $path_site . 'db.php';
|
||||||
$db_text = "<?php\n" . "// Processmaker configuration\n" . "define ('DB_ADAPTER', 'mysql' );\n" . "define ('DB_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_NAME', '" . $wf . "' );\n" . "define ('DB_USER', '" . (($this->cc_status == 1) ? $this->wf_user_db : $this->options['database']['username']) . "' );\n" . "define ('DB_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_RBAC_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_RBAC_NAME', '" . $rb . "' );\n" . "define ('DB_RBAC_USER', '" . (($this->cc_status == 1) ? $this->wf_user_db : $this->options['database']['username']) . "' );\n" . "define ('DB_RBAC_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n" . "define ('DB_REPORT_HOST', '" . $this->options['database']['hostname'] . ":" . $myPort . "' );\n" . "define ('DB_REPORT_NAME', '" . $rp . "' );\n" . "define ('DB_REPORT_USER', '" . (($this->cc_status == 1) ? $this->wf_user_db : $this->options['database']['username']) . "' );\n" . "define ('DB_REPORT_PASS', '" . (($this->cc_status == 1) ? $this->options['password'] : $this->options['database']['password']) . "' );\n";
|
$db_text = "<?php\n"
|
||||||
|
. "// Processmaker configuration\n"
|
||||||
|
. " define ('DB_ADAPTER', 'mysql' );\n"
|
||||||
|
. " define ('DB_HOST', '" . $hostname . "' );\n"
|
||||||
|
. " define ('DB_NAME', '" . $wf . "' );\n"
|
||||||
|
. " define ('DB_USER', '" . $username . "' );\n"
|
||||||
|
. " define ('DB_PASS', '" . $password . "' );\n"
|
||||||
|
. " define ('DB_RBAC_HOST', '" . $hostname . "' );\n"
|
||||||
|
. " define ('DB_RBAC_NAME', '" . $rb . "' );\n"
|
||||||
|
. " define ('DB_RBAC_USER', '" . $username . "' );\n"
|
||||||
|
. " define ('DB_RBAC_PASS', '" . $password . "' );\n"
|
||||||
|
. " define ('DB_REPORT_HOST', '" . $hostname . "' );\n"
|
||||||
|
. " define ('DB_REPORT_NAME', '" . $rp . "' );\n"
|
||||||
|
. " define ('DB_REPORT_USER', '" . $username . "' );\n"
|
||||||
|
. " define ('DB_REPORT_PASS', '" . $password . "' );\n"
|
||||||
|
. "";
|
||||||
|
|
||||||
if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) {
|
if (defined('PARTNER_FLAG') || isset($_REQUEST['PARTNER_FLAG'])) {
|
||||||
$db_text .= "define ('PARTNER_FLAG', " . ((defined('PARTNER_FLAG') && PARTNER_FLAG != '') ? PARTNER_FLAG : ((isset($_REQUEST['PARTNER_FLAG'])) ? $_REQUEST['PARTNER_FLAG'] : 'false')) . ");\n";
|
$db_text .= "define ('PARTNER_FLAG', " . ((defined('PARTNER_FLAG') && PARTNER_FLAG != '') ? PARTNER_FLAG : ((isset($_REQUEST['PARTNER_FLAG'])) ? $_REQUEST['PARTNER_FLAG'] : 'false')) . ");\n";
|
||||||
if (defined('SYSTEM_NAME')) {
|
if (defined('SYSTEM_NAME')) {
|
||||||
@@ -207,7 +279,7 @@ class Installer
|
|||||||
|
|
||||||
$fp = @fopen($db_file, "w");
|
$fp = @fopen($db_file, "w");
|
||||||
$this->log("Create: " . $db_file . " => " . ((!$fp) ? $fp : "OK") . "\n", $fp === false);
|
$this->log("Create: " . $db_file . " => " . ((!$fp) ? $fp : "OK") . "\n", $fp === false);
|
||||||
$ff = @fputs($fp, $db_text, strlen($db_text));
|
$ff = @fwrite($fp, $db_text, strlen($db_text));
|
||||||
$this->log("Write: " . $db_file . " => " . ((!$ff) ? $ff : "OK") . "\n", $ff === false);
|
$this->log("Write: " . $db_file . " => " . ((!$ff) ? $ff : "OK") . "\n", $ff === false);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
@@ -218,7 +290,7 @@ class Installer
|
|||||||
|
|
||||||
$fp = @fopen($envIniFile, 'w');
|
$fp = @fopen($envIniFile, 'w');
|
||||||
$this->log('Create: ' . $envIniFile . ' => ' . ((!$fp) ? $fp : 'OK') . "\n", $fp === false);
|
$this->log('Create: ' . $envIniFile . ' => ' . ((!$fp) ? $fp : 'OK') . "\n", $fp === false);
|
||||||
$ff = @fputs($fp, $content, strlen($content));
|
$ff = @fwrite($fp, $content, strlen($content));
|
||||||
$this->log('Write: ' . $envIniFile . ' => ' . ((!$ff) ? $ff : 'OK') . "\n", $ff === false);
|
$this->log('Write: ' . $envIniFile . ' => ' . ((!$ff) ? $ff : 'OK') . "\n", $ff === false);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
/*----------------------------------********---------------------------------*/
|
/*----------------------------------********---------------------------------*/
|
||||||
@@ -227,9 +299,12 @@ class Installer
|
|||||||
$this->setPartner();
|
$this->setPartner();
|
||||||
$this->setAdmin();
|
$this->setAdmin();
|
||||||
|
|
||||||
$querySql = "INSERT INTO EMAIL_SERVER(MESS_UID, MESS_ENGINE) VALUES('" . \ProcessMaker\Util\Common::generateUID() . "', 'MAIL')";
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
|
->table('EMAIL_SERVER')
|
||||||
$this->run_query($querySql);
|
->insert([
|
||||||
|
'MESS_UID' => Common::generateUID(),
|
||||||
|
'MESS_ENGINE' => 'MAIL'
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
return $test;
|
return $test;
|
||||||
}
|
}
|
||||||
@@ -246,10 +321,9 @@ class Installer
|
|||||||
// Execute sql for partner
|
// Execute sql for partner
|
||||||
$pathMysqlPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'mysql' . PATH_SEP;
|
$pathMysqlPartner = PATH_CORE . 'data' . PATH_SEP . 'partner' . PATH_SEP . 'mysql' . PATH_SEP;
|
||||||
if (G::verifyPath($pathMysqlPartner)) {
|
if (G::verifyPath($pathMysqlPartner)) {
|
||||||
$res = [];
|
|
||||||
$filesSlq = glob($pathMysqlPartner . '*.sql');
|
$filesSlq = glob($pathMysqlPartner . '*.sql');
|
||||||
foreach ($filesSlq as $value) {
|
foreach ($filesSlq as $value) {
|
||||||
$this->query_sql_file($value, $this->connection_database);
|
$this->query_sql_file($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,10 +480,10 @@ class Installer
|
|||||||
*/
|
*/
|
||||||
public function setConfiguration()
|
public function setConfiguration()
|
||||||
{
|
{
|
||||||
$oConf = new Configuration();
|
$configuration = new Configuration();
|
||||||
$dataCondif = $oConf->getAll();
|
$dataConfig = $configuration->getAll();
|
||||||
if (count($dataCondif)) {
|
if (count($dataConfig)) {
|
||||||
foreach ($dataCondif as $value) {
|
foreach ($dataConfig as $value) {
|
||||||
if ($value['CFG_UID'] == 'ENVIRONMENT_SETTINGS') {
|
if ($value['CFG_UID'] == 'ENVIRONMENT_SETTINGS') {
|
||||||
$query = 'INSERT INTO CONFIGURATION (CFG_UID, OBJ_UID, CFG_VALUE, PRO_UID, USR_UID, APP_UID) VALUES';
|
$query = 'INSERT INTO CONFIGURATION (CFG_UID, OBJ_UID, CFG_VALUE, PRO_UID, USR_UID, APP_UID) VALUES';
|
||||||
$query .= "('" .
|
$query .= "('" .
|
||||||
@@ -419,7 +493,6 @@ class Installer
|
|||||||
$value['PRO_UID'] . "', '" .
|
$value['PRO_UID'] . "', '" .
|
||||||
$value['USR_UID'] . "', '" .
|
$value['USR_UID'] . "', '" .
|
||||||
$value['APP_UID'] . "')";
|
$value['APP_UID'] . "')";
|
||||||
mysqli_select_db($this->connection_database, $this->wf_site_name);
|
|
||||||
$this->run_query($query, "Copy configuracion environment");
|
$this->run_query($query, "Copy configuracion environment");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -434,59 +507,92 @@ class Installer
|
|||||||
*/
|
*/
|
||||||
public function setAdmin()
|
public function setAdmin()
|
||||||
{
|
{
|
||||||
mysqli_select_db($this->connection_database, $this->wf_site_name);
|
// Change admin user
|
||||||
// The mysql_escape_string function has been DEPRECATED as of PHP 5.3.0.
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
// $this->run_query('UPDATE USERS SET USR_USERNAME = \''.mysqli_escape_string($this->options['admin']['username']).'\', `USR_PASSWORD` = \''.md5($this->options['admin']['password']).'\' WHERE `USR_UID` = \'00000000000000000000000000000001\' LIMIT 1',
|
->table('USERS')
|
||||||
// "Add 'admin' user in ProcessMaker (wf)");
|
->where('USR_UID', '00000000000000000000000000000001')
|
||||||
$this->run_query('UPDATE USERS SET USR_USERNAME = \'' . mysqli_real_escape_string($this->connection_database, $this->options['admin']['username']) . '\', ' . ' `USR_PASSWORD` = \'' . G::encryptHash($this->options['admin']['password']) . '\' ' . ' WHERE `USR_UID` = \'00000000000000000000000000000001\' LIMIT 1', "Add 'admin' user in ProcessMaker (wf)");
|
->update([
|
||||||
mysqli_select_db($this->connection_database, $this->rbac_site_name);
|
'USR_USERNAME' => $this->options['admin']['username'],
|
||||||
// The mysql_escape_string function has been DEPRECATED as of PHP 5.3.0.
|
'USR_PASSWORD' => Bootstrap::hashPassword($this->options['admin']['password'], Bootstrap::hashBcrypt)
|
||||||
// $this->run_query('UPDATE USERS SET USR_USERNAME = \''.mysqli_escape_string($this->options['admin']['username']).'\', `USR_PASSWORD` = \''.md5($this->options['admin']['password']).'\' WHERE `USR_UID` = \'00000000000000000000000000000001\' LIMIT 1',
|
]);
|
||||||
// "Add 'admin' user in ProcessMaker (rb)");
|
|
||||||
$this->run_query('UPDATE RBAC_USERS SET USR_USERNAME = \'' . mysqli_real_escape_string($this->connection_database, $this->options['admin']['username']) . '\', ' . ' `USR_PASSWORD` = \'' . G::encryptHash($this->options['admin']['password']) . '\' ' . ' WHERE `USR_UID` = \'00000000000000000000000000000001\' LIMIT 1', "Add 'admin' user in ProcessMaker (rb)");
|
DB::connection(self::CONNECTION_INSTALL)
|
||||||
|
->table('RBAC_USERS')
|
||||||
|
->where('USR_UID', '00000000000000000000000000000001')
|
||||||
|
->update([
|
||||||
|
'USR_USERNAME' => $this->options['admin']['username'],
|
||||||
|
'USR_PASSWORD' => Bootstrap::hashPassword($this->options['admin']['password'], Bootstrap::hashBcrypt)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a mysql query on the current database and take care of logging and
|
* Run a mysql script on the current database and take care of logging and
|
||||||
* error handling.
|
* error handling.
|
||||||
*
|
*
|
||||||
* @param string $query SQL command
|
* @param string $query SQL command
|
||||||
* @param string $description Description to log instead of $query
|
* @param string $description Description to log instead of $query
|
||||||
|
* @param string $connection default connection install
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function run_query($query, $description = null)
|
private function runTrigger($query, $description = '', $connection = self::CONNECTION_INSTALL)
|
||||||
{
|
{
|
||||||
$result = mysqli_query($this->connection_database, $query);
|
$this->run_query($query, $description, $connection, 'RAW');
|
||||||
$error = $result ? false : mysqli_error($this->connection_database);
|
|
||||||
$this->log(($description ? $description : $query) . " => " . (($error) ? $error : "OK") . "\n", $error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* query_sql_file
|
* Run a mysql query on the current database and take care of logging and
|
||||||
|
* error handling.
|
||||||
*
|
*
|
||||||
* @param string $file
|
* @param string $query SQL command
|
||||||
* @param string $connection
|
* @param string $description Description to log instead of $query
|
||||||
* @return array $report
|
* @param string $connection default connection install
|
||||||
|
* @param string $type STATEMENT|RAW
|
||||||
*/
|
*/
|
||||||
public function query_sql_file($file, $connection)
|
private function run_query($query, $description = '', $connection = self::CONNECTION_INSTALL, $type = 'STATEMENT')
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$message = '';
|
||||||
|
switch ($type) {
|
||||||
|
case 'STATEMENT':
|
||||||
|
DB::connection($connection)->statement($query);
|
||||||
|
break;
|
||||||
|
case 'RAW':
|
||||||
|
DB::connection($connection)->raw($query);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (QueryException $exception) {
|
||||||
|
$message = $exception->getMessage();
|
||||||
|
}
|
||||||
|
$this->log(!empty($description) ? $description : $query . ' => ' . (!empty($message) ? $message : 'OK') . "\n", !empty($message));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query sql file
|
||||||
|
*
|
||||||
|
* @param $file
|
||||||
|
* @param string $connection
|
||||||
|
*/
|
||||||
|
public function query_sql_file($file, $connection = self::CONNECTION_INSTALL)
|
||||||
{
|
{
|
||||||
$lines = file($file);
|
$lines = file($file);
|
||||||
$previous = null;
|
$previous = null;
|
||||||
$errors = '';
|
$errors = '';
|
||||||
mysqli_query($connection, "SET NAMES 'utf8';");
|
DB::connection($connection)
|
||||||
|
->statement("SET NAMES 'utf8'");
|
||||||
foreach ($lines as $j => $line) {
|
foreach ($lines as $j => $line) {
|
||||||
$line = trim($line); // Remove comments from the script
|
$line = trim($line); // Remove comments from the script
|
||||||
|
|
||||||
|
if (strpos($line, '--') === 0) {
|
||||||
if (strpos($line, "--") === 0) {
|
$line = substr($line, 0, strpos($line, '--'));
|
||||||
$line = substr($line, 0, strpos($line, "--"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($line)) {
|
if (empty($line)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($line, "#") === 0) {
|
if (strpos($line, '#') === 0) {
|
||||||
$line = substr($line, 0, strpos($line, "#"));
|
$line = substr($line, 0, strpos($line, '#'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($line)) {
|
if (empty($line)) {
|
||||||
@@ -495,32 +601,23 @@ class Installer
|
|||||||
|
|
||||||
// Concatenate the previous line, if any, with the current
|
// Concatenate the previous line, if any, with the current
|
||||||
if ($previous) {
|
if ($previous) {
|
||||||
$line = $previous . " " . $line;
|
$line = $previous . ' ' . $line;
|
||||||
}
|
}
|
||||||
$previous = null;
|
$previous = null;
|
||||||
|
|
||||||
// If the current line doesnt end with ; then put this line together
|
// If the current line doesnt end with ; then put this line together
|
||||||
// with the next one, thus supporting multi-line statements.
|
// with the next one, thus supporting multi-line statements.
|
||||||
if (strrpos($line, ";") != strlen($line) - 1) {
|
if (strrpos($line, ';') != strlen($line) - 1) {
|
||||||
$previous = $line;
|
$previous = $line;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$line = substr($line, 0, strrpos($line, ";"));
|
$line = substr($line, 0, strrpos($line, ';'));
|
||||||
mysqli_query($connection, $line);
|
DB::connection($connection)
|
||||||
|
->statement($line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* check_path
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
* @todo Empty function
|
|
||||||
*/
|
|
||||||
private function check_path()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function find_root_path
|
* function find_root_path
|
||||||
*
|
*
|
||||||
@@ -573,7 +670,7 @@ class Installer
|
|||||||
* getDirectoryFiles
|
* getDirectoryFiles
|
||||||
*
|
*
|
||||||
* @param string $dir default value empty
|
* @param string $dir default value empty
|
||||||
* @return string $path
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getDirectoryFiles($dir, $extension)
|
public function getDirectoryFiles($dir, $extension)
|
||||||
{
|
{
|
||||||
@@ -595,17 +692,24 @@ class Installer
|
|||||||
/**
|
/**
|
||||||
* check_db_empty
|
* check_db_empty
|
||||||
*
|
*
|
||||||
* @param string $dbName
|
* @param string$dbName
|
||||||
* @return boolean true or false
|
* @return boolean true or false
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function check_db_empty($dbName)
|
public function check_db_empty($dbName)
|
||||||
{
|
{
|
||||||
$a = mysqli_select_db($this->connection_database, $dbName);
|
try
|
||||||
if (!$a) {
|
{
|
||||||
return true;
|
$result = DB::connection(self::CONNECTION_TEST_INSTALL)->select("show databases like '$dbName'");
|
||||||
|
if (!$result) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$result = DB::connection(self::CONNECTION_TEST_INSTALL)->select("show tables from $dbName");
|
||||||
|
return !$result;
|
||||||
|
}
|
||||||
|
} catch (QueryException $exception) {
|
||||||
|
throw new Exception('User without permissions. ' . $exception->getMessage());
|
||||||
}
|
}
|
||||||
$q = mysqli_query($this->connection_database, 'SHOW TABLES');
|
|
||||||
return !(mysqli_num_rows($q) > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -621,10 +725,10 @@ class Installer
|
|||||||
$response['message'] = '';
|
$response['message'] = '';
|
||||||
if (!$this->connection_database) {
|
if (!$this->connection_database) {
|
||||||
//new verification if the mysql extension is enabled
|
//new verification if the mysql extension is enabled
|
||||||
$response['message'] = class_exists('mysql_error') ? mysqli_error() : 'Mysql Module for PHP is not enabled!';
|
$response['message'] = 'Mysql Module for PHP is not enabled!';
|
||||||
} else {
|
} else {
|
||||||
if (!mysqli_select_db($this->connection_database, $dbName) && $this->cc_status != 1) {
|
if ($this->cc_status != 1) {
|
||||||
$response['message'] = mysqli_error($this->connection_database);
|
$result = DB::connection(self::CONNECTION_TEST_INSTALL)->select("show databases like '$dbName'");
|
||||||
} else {
|
} else {
|
||||||
if ($this->options['advanced']['ao_db_drop'] === true || $this->check_db_empty($dbName)) {
|
if ($this->options['advanced']['ao_db_drop'] === true || $this->check_db_empty($dbName)) {
|
||||||
$response['status'] = true;
|
$response['status'] = true;
|
||||||
@@ -640,52 +744,79 @@ class Installer
|
|||||||
/**
|
/**
|
||||||
* check_connection
|
* check_connection
|
||||||
*
|
*
|
||||||
* @return Array $rt
|
* @return array $rt
|
||||||
*/
|
*/
|
||||||
private function check_connection()
|
private function check_connection($nameConnection)
|
||||||
{
|
{
|
||||||
if (!function_exists('mysqli_connect')) {
|
$this->cc_status = 0;
|
||||||
$this->cc_status = 0;
|
$rt = [
|
||||||
$rt = array('connection' => false, 'grant' => 0, 'version' => false, 'message' => "ERROR: Mysql Module for PHP is not enabled, try install <b>php-mysql</b> package.", 'ao' => array('ao_db_wf' => false, 'ao_db_rb' => false, 'ao_db_rp' => false
|
'connection' => false,
|
||||||
)
|
'grant' => 0,
|
||||||
);
|
'version' => false,
|
||||||
} else {
|
'message' => 'ERROR: Mysql Module for PHP is not enabled, try install <b>php-mysqli</b> package.',
|
||||||
$this->connection_database = mysqli_connect($this->options['database']['hostname'], $this->options['database']['username'], $this->options['database']['password']);
|
'ao' => [
|
||||||
$rt = array('version' => false, 'ao' => array('ao_db_wf' => false, 'ao_db_rb' => false, 'ao_db_rp' => false
|
'ao_db_wf' => false,
|
||||||
)
|
'ao_db_rb' => false,
|
||||||
);
|
'ao_db_rp' => false
|
||||||
if (!$this->connection_database) {
|
]
|
||||||
$this->cc_status = 0;
|
];
|
||||||
$rt['connection'] = false;
|
|
||||||
$rt['grant'] = 0;
|
if (function_exists('mysqli_connect')) {
|
||||||
$rt['message'] = 'Mysql error: ' . mysqli_error($this->connection_database);
|
try {
|
||||||
} else {
|
InstallerModule::setNewConnection(
|
||||||
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', mysqli_get_server_info($this->connection_database), $version);
|
$nameConnection,
|
||||||
$rt['version'] = version_compare(@$version[0], '4.1.0', '>=');
|
$this->options['database']['hostname'],
|
||||||
|
$this->options['database']['username'],
|
||||||
|
$this->options['database']['password'],
|
||||||
|
'',
|
||||||
|
$this->options['database']['port']);
|
||||||
|
$rt = [
|
||||||
|
'version' => false,
|
||||||
|
'ao' => [
|
||||||
|
'ao_db_wf' => false,
|
||||||
|
'ao_db_rb' => false,
|
||||||
|
'ao_db_rp' => false
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$results = DB::connection($nameConnection)->select(DB::raw('select version()'));
|
||||||
|
|
||||||
|
preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $results[0]->{'version()'}, $version);
|
||||||
|
$rt['version'] = version_compare($mysql_version = $version[0], '4.1.0', '>=');
|
||||||
$rt['connection'] = true;
|
$rt['connection'] = true;
|
||||||
|
|
||||||
$dbNameTest = 'PROCESSMAKERTESTDC';
|
$dbNameTest = 'PROCESSMAKERTESTDC';
|
||||||
$db = mysqli_query($this->connection_database, 'CREATE DATABASE ' . $dbNameTest);
|
$db = DB::connection($nameConnection)->statement("CREATE DATABASE IF NOT EXISTS $dbNameTest");
|
||||||
|
$this->connection_database = true;
|
||||||
|
|
||||||
if (!$db) {
|
if (!$db) {
|
||||||
$this->cc_status = 3;
|
$this->cc_status = 3;
|
||||||
$rt['grant'] = 3;
|
$rt['grant'] = 3;
|
||||||
$rt['message'] = 'Successful connection';
|
$rt['message'] = 'Successful connection';
|
||||||
} else {
|
} else {
|
||||||
$usrTest = "wfrbtest";
|
$usrTest = 'wfrbtest';
|
||||||
$chkG = "GRANT ALL PRIVILEGES ON `" . $dbNameTest . "`.* TO " . $usrTest . "@'%' IDENTIFIED BY 'sample' WITH GRANT OPTION";
|
$chkG = "GRANT ALL PRIVILEGES ON `" . $dbNameTest . "`.* TO " . $usrTest . "@'%' IDENTIFIED BY '!Sample123' WITH GRANT OPTION";
|
||||||
$ch = mysqli_query($this->connection_database, $chkG);
|
$ch = DB::connection($nameConnection)
|
||||||
|
->statement($chkG);
|
||||||
|
|
||||||
if (!$ch) {
|
if (!$ch) {
|
||||||
$this->cc_status = 2;
|
$this->cc_status = 2;
|
||||||
$rt['grant'] = 2;
|
$rt['grant'] = 2;
|
||||||
$rt['message'] = 'Successful connection';
|
$rt['message'] = 'Successful connection';
|
||||||
} else {
|
} else {
|
||||||
$this->cc_status = 1;
|
$this->cc_status = 1;
|
||||||
mysqli_query($this->connection_database, "DROP USER " . $usrTest . "@'%'");
|
DB::connection($nameConnection)
|
||||||
|
->statement("DROP USER " . $usrTest . "@'%'");
|
||||||
$rt['grant'] = 1;
|
$rt['grant'] = 1;
|
||||||
$rt['message'] = 'Successful connection';
|
$rt['message'] = 'Successful connection';
|
||||||
}
|
}
|
||||||
mysqli_query($this->connection_database, 'DROP DATABASE ' . $dbNameTest);
|
DB::connection($nameConnection)
|
||||||
|
->statement('DROP DATABASE ' . $dbNameTest);
|
||||||
}
|
}
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$rt['connection'] = false;
|
||||||
|
$rt['grant'] = 0;
|
||||||
|
$rt['message'] = 'Mysql error: ' . $exception->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$rt['ao']['ao_db_wf'] = $this->check_db($this->options['advanced']['ao_db_wf']);
|
$rt['ao']['ao_db_wf'] = $this->check_db($this->options['advanced']['ao_db_wf']);
|
||||||
@@ -693,14 +824,15 @@ class Installer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* log
|
* Log
|
||||||
*
|
*
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @return void
|
* @param boolean $failed
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function log($text, $failed = null)
|
public function log($text, $failed = false)
|
||||||
{
|
{
|
||||||
array_push($this->report, $text);
|
$this->report[] = $text;
|
||||||
if ($failed) {
|
if ($failed) {
|
||||||
throw new Exception(is_string($text) ? $text : var_export($text, true));
|
throw new Exception(is_string($text) ? $text : var_export($text, true));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ namespace ProcessMaker\Core;
|
|||||||
use Configurations;
|
use Configurations;
|
||||||
use DomDocument;
|
use DomDocument;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Faker;
|
||||||
use G;
|
use G;
|
||||||
use GzipFile;
|
use GzipFile;
|
||||||
|
use Illuminate\Database\QueryException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use InputFilter;
|
use InputFilter;
|
||||||
|
use InstallerModule;
|
||||||
|
use Net;
|
||||||
use schema;
|
use schema;
|
||||||
use WorkspaceTools;
|
use WorkspaceTools;
|
||||||
|
|
||||||
@@ -66,7 +71,7 @@ class System
|
|||||||
*/
|
*/
|
||||||
public static function getPlugins()
|
public static function getPlugins()
|
||||||
{
|
{
|
||||||
$plugins = array();
|
$plugins = [];
|
||||||
|
|
||||||
foreach (glob(PATH_PLUGINS . "*") as $filename) {
|
foreach (glob(PATH_PLUGINS . "*") as $filename) {
|
||||||
$info = pathinfo($filename);
|
$info = pathinfo($filename);
|
||||||
@@ -90,7 +95,7 @@ class System
|
|||||||
public static function listWorkspaces()
|
public static function listWorkspaces()
|
||||||
{
|
{
|
||||||
$oDirectory = dir(PATH_DB);
|
$oDirectory = dir(PATH_DB);
|
||||||
$aWorkspaces = array();
|
$aWorkspaces = [];
|
||||||
foreach (glob(PATH_DB . "*") as $filename) {
|
foreach (glob(PATH_DB . "*") as $filename) {
|
||||||
if (is_dir($filename) && file_exists($filename . "/db.php")) {
|
if (is_dir($filename) && file_exists($filename . "/db.php")) {
|
||||||
$aWorkspaces[] = new WorkspaceTools(basename($filename));
|
$aWorkspaces[] = new WorkspaceTools(basename($filename));
|
||||||
@@ -150,7 +155,7 @@ class System
|
|||||||
*/
|
*/
|
||||||
public static function getSysInfo()
|
public static function getSysInfo()
|
||||||
{
|
{
|
||||||
$ipe = isset($_SERVER['SSH_CONNECTION']) ? explode(" ", $_SERVER['SSH_CONNECTION']) : array();
|
$ipe = isset($_SERVER['SSH_CONNECTION']) ? explode(" ", $_SERVER['SSH_CONNECTION']) : [];
|
||||||
|
|
||||||
if (getenv('HTTP_CLIENT_IP')) {
|
if (getenv('HTTP_CLIENT_IP')) {
|
||||||
$ip = getenv('HTTP_CLIENT_IP');
|
$ip = getenv('HTTP_CLIENT_IP');
|
||||||
@@ -194,7 +199,7 @@ class System
|
|||||||
*/
|
*/
|
||||||
$distro = trim($distro, "\"") . " (" . PHP_OS . ")";
|
$distro = trim($distro, "\"") . " (" . PHP_OS . ")";
|
||||||
|
|
||||||
$Fields = array();
|
$Fields = [];
|
||||||
$Fields['SYSTEM'] = $distro;
|
$Fields['SYSTEM'] = $distro;
|
||||||
$Fields['PHP'] = phpversion();
|
$Fields['PHP'] = phpversion();
|
||||||
$Fields['PM_VERSION'] = self::getVersion();
|
$Fields['PM_VERSION'] = self::getVersion();
|
||||||
@@ -397,9 +402,9 @@ class System
|
|||||||
fwrite($fp, "");
|
fwrite($fp, "");
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
$aEnvironmentsUpdated = array();
|
$aEnvironmentsUpdated = [];
|
||||||
$aEnvironmentsDiff = array();
|
$aEnvironmentsDiff = [];
|
||||||
$aErrors = array();
|
$aErrors = [];
|
||||||
|
|
||||||
//now will verify each folder and file has permissions to write and add files.
|
//now will verify each folder and file has permissions to write and add files.
|
||||||
if ($this->sUpgradeFileList != '') {
|
if ($this->sUpgradeFileList != '') {
|
||||||
@@ -557,13 +562,13 @@ class System
|
|||||||
$oDirectory = dir(PATH_DB);
|
$oDirectory = dir(PATH_DB);
|
||||||
|
|
||||||
//count db.php files ( workspaces )
|
//count db.php files ( workspaces )
|
||||||
$aWorkspaces = array();
|
$aWorkspaces = [];
|
||||||
while (($sObject = $oDirectory->read())) {
|
while (($sObject = $oDirectory->read())) {
|
||||||
if (is_dir(PATH_DB . $sObject) && substr($sObject, 0, 1) != '.' && file_exists(PATH_DB . $sObject . PATH_SEP . 'db.php')) {
|
if (is_dir(PATH_DB . $sObject) && substr($sObject, 0, 1) != '.' && file_exists(PATH_DB . $sObject . PATH_SEP . 'db.php')) {
|
||||||
$aWorkspaces[] = $sObject;
|
$aWorkspaces[] = $sObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$aUpgradeData = array();
|
$aUpgradeData = [];
|
||||||
$aUpgradeData['workspaces'] = $aWorkspaces;
|
$aUpgradeData['workspaces'] = $aWorkspaces;
|
||||||
$aUpgradeData['wsQuantity'] = count($aWorkspaces);
|
$aUpgradeData['wsQuantity'] = count($aWorkspaces);
|
||||||
$aUpgradeData['sPoFile'] = $sPoFile;
|
$aUpgradeData['sPoFile'] = $sPoFile;
|
||||||
@@ -732,19 +737,28 @@ class System
|
|||||||
public static function getSchema($sSchemaFile)
|
public static function getSchema($sSchemaFile)
|
||||||
{
|
{
|
||||||
/* This is the MySQL mapping that Propel uses (from MysqlPlatform.php) */
|
/* This is the MySQL mapping that Propel uses (from MysqlPlatform.php) */
|
||||||
$mysqlTypes = array('NUMERIC' => "DECIMAL", 'LONGVARCHAR' => "MEDIUMTEXT", 'TIMESTAMP' => "DATETIME", 'BU_TIMESTAMP' => "DATETIME", 'BINARY' => "BLOB", 'VARBINARY' => "MEDIUMBLOB", 'LONGVARBINARY' => "LONGBLOB", 'BLOB' => "LONGBLOB", 'CLOB' => "LONGTEXT",
|
$mysqlTypes = [
|
||||||
|
'NUMERIC' => 'DECIMAL',
|
||||||
|
'LONGVARCHAR' => 'MEDIUMTEXT',
|
||||||
|
'TIMESTAMP' => 'DATETIME',
|
||||||
|
'BU_TIMESTAMP' => 'DATETIME',
|
||||||
|
'BINARY' => 'BLOB',
|
||||||
|
'VARBINARY' => 'MEDIUMBLOB',
|
||||||
|
'LONGVARBINARY' => 'LONGBLOB',
|
||||||
|
'BLOB' => 'LONGBLOB',
|
||||||
|
'CLOB' => 'LONGTEXT',
|
||||||
/* This is not from Propel, but is required to get INT right */
|
/* This is not from Propel, but is required to get INT right */
|
||||||
'INTEGER' => "INT"
|
'INTEGER' => 'INT'
|
||||||
);
|
];
|
||||||
|
|
||||||
$aSchema = array();
|
$aSchema = [];
|
||||||
$oXml = new DomDocument();
|
$oXml = new DomDocument();
|
||||||
$oXml->load($sSchemaFile);
|
$oXml->load($sSchemaFile);
|
||||||
$aTables = $oXml->getElementsByTagName('table');
|
$aTables = $oXml->getElementsByTagName('table');
|
||||||
foreach ($aTables as $oTable) {
|
foreach ($aTables as $oTable) {
|
||||||
$aPrimaryKeys = array();
|
$aPrimaryKeys = [];
|
||||||
$sTableName = $oTable->getAttribute('name');
|
$sTableName = $oTable->getAttribute('name');
|
||||||
$aSchema[$sTableName] = array();
|
$aSchema[$sTableName] = [];
|
||||||
$aColumns = $oTable->getElementsByTagName('column');
|
$aColumns = $oTable->getElementsByTagName('column');
|
||||||
foreach ($aColumns as $oColumn) {
|
foreach ($aColumns as $oColumn) {
|
||||||
$sColumName = $oColumn->getAttribute('name');
|
$sColumName = $oColumn->getAttribute('name');
|
||||||
@@ -801,7 +815,7 @@ class System
|
|||||||
}
|
}
|
||||||
$aIndexes = $oTable->getElementsByTagName('index');
|
$aIndexes = $oTable->getElementsByTagName('index');
|
||||||
foreach ($aIndexes as $oIndex) {
|
foreach ($aIndexes as $oIndex) {
|
||||||
$aIndex = array();
|
$aIndex = [];
|
||||||
$aIndexesColumns = $oIndex->getElementsByTagName('index-column');
|
$aIndexesColumns = $oIndex->getElementsByTagName('index-column');
|
||||||
foreach ($aIndexesColumns as $oIndexColumn) {
|
foreach ($aIndexesColumns as $oIndexColumn) {
|
||||||
$aIndex[] = $oIndexColumn->getAttribute('name');
|
$aIndex[] = $oIndexColumn->getAttribute('name');
|
||||||
@@ -820,7 +834,7 @@ class System
|
|||||||
*/
|
*/
|
||||||
public static function verifyRbacSchema($aOldSchema)
|
public static function verifyRbacSchema($aOldSchema)
|
||||||
{
|
{
|
||||||
$aChanges = array();
|
$aChanges = [];
|
||||||
|
|
||||||
foreach ($aOldSchema as $sTableName => $aColumns) {
|
foreach ($aOldSchema as $sTableName => $aColumns) {
|
||||||
if (substr($sTableName, 0, 4) != 'RBAC') {
|
if (substr($sTableName, 0, 4) != 'RBAC') {
|
||||||
@@ -936,13 +950,13 @@ class System
|
|||||||
foreach ($aNewSchema[$sTableName]['INDEXES'] as $indexName => $indexFields) {
|
foreach ($aNewSchema[$sTableName]['INDEXES'] as $indexName => $indexFields) {
|
||||||
if (!isset($aOldSchema[$sTableName]['INDEXES'][$indexName])) {
|
if (!isset($aOldSchema[$sTableName]['INDEXES'][$indexName])) {
|
||||||
if (!isset($aChanges['tablesWithNewIndex'][$sTableName])) {
|
if (!isset($aChanges['tablesWithNewIndex'][$sTableName])) {
|
||||||
$aChanges['tablesWithNewIndex'][$sTableName] = array();
|
$aChanges['tablesWithNewIndex'][$sTableName] = [];
|
||||||
}
|
}
|
||||||
$aChanges['tablesWithNewIndex'][$sTableName][$indexName] = $indexFields;
|
$aChanges['tablesWithNewIndex'][$sTableName][$indexName] = $indexFields;
|
||||||
} else {
|
} else {
|
||||||
if ($aOldSchema[$sTableName]['INDEXES'][$indexName] != $indexFields) {
|
if ($aOldSchema[$sTableName]['INDEXES'][$indexName] != $indexFields) {
|
||||||
if (!isset($aChanges['tablesToAlterIndex'][$sTableName])) {
|
if (!isset($aChanges['tablesToAlterIndex'][$sTableName])) {
|
||||||
$aChanges['tablesToAlterIndex'][$sTableName] = array();
|
$aChanges['tablesToAlterIndex'][$sTableName] = [];
|
||||||
}
|
}
|
||||||
$aChanges['tablesToAlterIndex'][$sTableName][$indexName] = $indexFields;
|
$aChanges['tablesToAlterIndex'][$sTableName][$indexName] = $indexFields;
|
||||||
}
|
}
|
||||||
@@ -1007,11 +1021,11 @@ class System
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Get Skin Config files
|
//Get Skin Config files
|
||||||
$skinListArray = array();
|
$skinListArray = [];
|
||||||
$customSkins = glob(PATH_CUSTOM_SKINS . "*/config.xml");
|
$customSkins = glob(PATH_CUSTOM_SKINS . "*/config.xml");
|
||||||
|
|
||||||
if (!is_array($customSkins)) {
|
if (!is_array($customSkins)) {
|
||||||
$customSkins = array();
|
$customSkins = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// getting al base skins
|
// getting al base skins
|
||||||
@@ -1045,7 +1059,7 @@ class System
|
|||||||
|
|
||||||
if (isset($xmlConfigurationObj->result['skinConfiguration'])) {
|
if (isset($xmlConfigurationObj->result['skinConfiguration'])) {
|
||||||
$skinInformationArray = $skinFilesArray = $xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['information']['__CONTENT__'];
|
$skinInformationArray = $skinFilesArray = $xmlConfigurationObj->result['skinConfiguration']['__CONTENT__']['information']['__CONTENT__'];
|
||||||
$res = array();
|
$res = [];
|
||||||
$res['SKIN_FOLDER_ID'] = strtolower($folderId);
|
$res['SKIN_FOLDER_ID'] = strtolower($folderId);
|
||||||
|
|
||||||
foreach ($skinInformationArray as $keyInfo => $infoValue) {
|
foreach ($skinInformationArray as $keyInfo => $infoValue) {
|
||||||
@@ -1171,7 +1185,7 @@ class System
|
|||||||
*/
|
*/
|
||||||
public static function getQueryBlackList($globalIniFile = '')
|
public static function getQueryBlackList($globalIniFile = '')
|
||||||
{
|
{
|
||||||
$config = array();
|
$config = [];
|
||||||
if (empty($globalIniFile)) {
|
if (empty($globalIniFile)) {
|
||||||
$blackListIniFile = PATH_CONFIG . 'execute-query-blacklist.ini';
|
$blackListIniFile = PATH_CONFIG . 'execute-query-blacklist.ini';
|
||||||
$sysTablesIniFile = PATH_CONFIG . 'system-tables.ini';
|
$sysTablesIniFile = PATH_CONFIG . 'system-tables.ini';
|
||||||
@@ -1320,5 +1334,179 @@ class System
|
|||||||
|
|
||||||
return $serverVersion;
|
return $serverVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate user name for test
|
||||||
|
*
|
||||||
|
* @param int $length
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function generateUserName($length = 10)
|
||||||
|
{
|
||||||
|
$userName = 'PM_';
|
||||||
|
for ($i = 0; $i < $length - 3; $i++) {
|
||||||
|
$userName .= ($i % 3) === 0 ? '?' : '#';
|
||||||
|
}
|
||||||
|
$faker = Faker\Factory::create();
|
||||||
|
return $faker->bothify($userName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check permission the user in db
|
||||||
|
*
|
||||||
|
* @param string $adapter
|
||||||
|
* @param string $serverName
|
||||||
|
* @param int $port
|
||||||
|
* @param string $userName
|
||||||
|
* @param string $pass
|
||||||
|
* @param string $dbName
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function checkPermissionsDbUser($adapter = 'mysql', $serverName, $port = 3306, $userName, $pass, $dbName = '')
|
||||||
|
{
|
||||||
|
if (empty($port)) {
|
||||||
|
//setting defaults ports
|
||||||
|
switch ($adapter) {
|
||||||
|
case 'mysql':
|
||||||
|
$port = 3306;
|
||||||
|
break;
|
||||||
|
case 'pgsql':
|
||||||
|
$port = 5432;
|
||||||
|
break;
|
||||||
|
case 'mssql':
|
||||||
|
$port = 1433;
|
||||||
|
break;
|
||||||
|
case 'oracle':
|
||||||
|
$port = 1521;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$filter = new InputFilter();
|
||||||
|
$serverName = $filter->validateInput($serverName);
|
||||||
|
$userName = $filter->validateInput($userName);
|
||||||
|
|
||||||
|
$serverNet = new Net($serverName);
|
||||||
|
if ($serverNet->getErrno() !== 0) {
|
||||||
|
return [false, $serverNet->error];
|
||||||
|
}
|
||||||
|
$serverNet->scannPort($port);
|
||||||
|
if ($serverNet->getErrno() !== 0) {
|
||||||
|
return [false, $serverNet->error];
|
||||||
|
}
|
||||||
|
$serverNet->loginDbServer($userName, $pass);
|
||||||
|
$serverNet->setDataBase('', $port);
|
||||||
|
if ($serverNet->getErrno() !== 0) {
|
||||||
|
return [false, $serverNet->error];
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $serverNet->tryConnectServer($adapter);
|
||||||
|
if (!empty($response) && $response->status !== 'SUCCESS' && $serverNet->getErrno() !== 0) {
|
||||||
|
return [false, $serverNet->error];
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$success = false;
|
||||||
|
|
||||||
|
$userName = $filter->validateInput($userName, 'nosql');
|
||||||
|
try {
|
||||||
|
$connection = 'SYSTEM';
|
||||||
|
InstallerModule::setNewConnection($connection, $serverName, $userName, $pass, $dbName, $port);
|
||||||
|
|
||||||
|
//Test Create Database
|
||||||
|
$dbNameTest = 'PROCESSMAKERTESTDC';
|
||||||
|
$result = DB::connection($connection)->statement("CREATE DATABASE $dbNameTest");
|
||||||
|
if ($result) {
|
||||||
|
//Test set permissions user
|
||||||
|
$usrTest = self::generateUserName(strlen($userName));
|
||||||
|
$passTest = '!Sample123_';
|
||||||
|
$result = DB::connection($connection)->statement("GRANT ALL PRIVILEGES ON `$dbNameTest`.* TO $usrTest@'%%' IDENTIFIED BY '$passTest' WITH GRANT OPTION");
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
//Test Create user
|
||||||
|
$userTestCreate = self::generateUserName(strlen($userName));
|
||||||
|
$result = DB::connection($connection)->statement("CREATE USER '$userTestCreate'@'%%' IDENTIFIED BY '$passTest'");
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$success = true;
|
||||||
|
$message = G::LoadTranslation('ID_SUCCESSFUL_CONNECTION');
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::connection($connection)->statement("DROP USER '$userTestCreate'@'%%'");
|
||||||
|
DB::connection($connection)->statement("DROP USER '$usrTest'@'%%'");
|
||||||
|
}
|
||||||
|
DB::connection($connection)->statement("DROP DATABASE $dbNameTest");
|
||||||
|
}
|
||||||
|
} catch (Exception $exception) {
|
||||||
|
$success = false;
|
||||||
|
$message = $exception->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return [$success, !empty($message) ? $message : $serverNet->error];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regenerate credentials paths installed
|
||||||
|
*
|
||||||
|
* @param string $host
|
||||||
|
* @param string $user
|
||||||
|
* @param string $pass
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function regenerateCredentiaslPathInstalled($host, $user, $pass)
|
||||||
|
{
|
||||||
|
$hashOld = G::encryptOld(filemtime(PATH_GULLIVER . "/class.g.php"));
|
||||||
|
$hash = G::encrypt($host . $hashOld . $user . $hashOld . $pass . $hashOld . (1), $hashOld);
|
||||||
|
$insertStatements = "define ( 'HASH_INSTALLATION','{$hash}' ); \ndefine ( 'SYSTEM_HASH', '{$hashOld}' ); \n";
|
||||||
|
$content = '';
|
||||||
|
$filename = PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths_installed.php';
|
||||||
|
$lines = file($filename);
|
||||||
|
|
||||||
|
$count = 1;
|
||||||
|
foreach ($lines as $line_num => $line) {
|
||||||
|
$pos = strpos($line, 'define');
|
||||||
|
if ($pos !== false && $count < 3) {
|
||||||
|
$content .= $line;
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$content = "<?php \n" . $content . "\n" . $insertStatements . "\n";
|
||||||
|
return file_put_contents($filename, $content) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Connection Configuration using "config" helper from "Laravel" with
|
||||||
|
* the constants defined in file "db.php"
|
||||||
|
*/
|
||||||
|
public static function setConnectionConfig(
|
||||||
|
$dbAdapter,
|
||||||
|
$dbHost,
|
||||||
|
$dbName,
|
||||||
|
$dbUser,
|
||||||
|
$dbPass,
|
||||||
|
$dbRbacHost,
|
||||||
|
$dbRbacName,
|
||||||
|
$dbRbacUser,
|
||||||
|
$dbRbacPass,
|
||||||
|
$dbReportHost,
|
||||||
|
$dbReportName,
|
||||||
|
$dbReportUser,
|
||||||
|
$dbReportPass)
|
||||||
|
{
|
||||||
|
config(['connections.driver' => $dbAdapter]);
|
||||||
|
config(['connections.workflow.host' => $dbHost]);
|
||||||
|
config(['connections.workflow.database' => $dbName]);
|
||||||
|
config(['connections.workflow.username' => $dbUser]);
|
||||||
|
config(['connections.workflow.password' => $dbPass]);
|
||||||
|
config(['connections.rbac.host' => $dbRbacHost]);
|
||||||
|
config(['connections.rbac.database' => $dbRbacName]);
|
||||||
|
config(['connections.rbac.username' => $dbRbacUser]);
|
||||||
|
config(['connections.rbac.password' => $dbRbacPass]);
|
||||||
|
config(['connections.report.host' => $dbReportHost]);
|
||||||
|
config(['connections.report.database' => $dbReportName]);
|
||||||
|
config(['connections.report.username' => $dbReportUser]);
|
||||||
|
config(['connections.report.password' => $dbReportPass]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// end System class
|
// end System class
|
||||||
|
|||||||
Reference in New Issue
Block a user