forked from Wavyzz/dolibarr
Debug v18 - warnings and pgsql migration
This commit is contained in:
@@ -26,10 +26,10 @@
|
||||
* Config is stored into file conf.php
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class to stock current configuration
|
||||
*/
|
||||
#[AllowDynamicProperties]
|
||||
class Conf
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -163,9 +163,10 @@ function versiondolibarrarray()
|
||||
* @param int $offsetforchartofaccount Offset to use to load chart of account table to update sql on the fly to add offset to rowid and account_parent value
|
||||
* @param int $colspan 2=Add a colspan=2 on td
|
||||
* @param int $onlysqltoimportwebsite Only sql resquests used to import a website template are allowed
|
||||
* @param string $database Database (replace __DATABASE__ with this value)
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
*/
|
||||
function run_sql($sqlfile, $silent = 1, $entity = '', $usesavepoint = 1, $handler = '', $okerror = 'default', $linelengthlimit = 32768, $nocommentremoval = 0, $offsetforchartofaccount = 0, $colspan = 0, $onlysqltoimportwebsite = 0)
|
||||
function run_sql($sqlfile, $silent = 1, $entity = 0, $usesavepoint = 1, $handler = '', $okerror = 'default', $linelengthlimit = 32768, $nocommentremoval = 0, $offsetforchartofaccount = 0, $colspan = 0, $onlysqltoimportwebsite = 0, $database = '')
|
||||
{
|
||||
global $db, $conf, $langs, $user;
|
||||
|
||||
@@ -327,7 +328,7 @@ function run_sql($sqlfile, $silent = 1, $entity = '', $usesavepoint = 1, $handle
|
||||
if ($sql) {
|
||||
// Test if th SQL is allowed SQL
|
||||
if ($onlysqltoimportwebsite) {
|
||||
$newsql = str_replace(array("\'"), '__BACKSLASHQUOTE__', $sql); // Replace the \' seque,ce
|
||||
$newsql = str_replace(array("\'"), '__BACKSLASHQUOTE__', $sql); // Replace the \' char
|
||||
|
||||
// Remove all strings contents including the ' so we can analyse SQL instruction only later
|
||||
$l = strlen($newsql);
|
||||
@@ -389,6 +390,10 @@ function run_sql($sqlfile, $silent = 1, $entity = '', $usesavepoint = 1, $handle
|
||||
$sql = preg_replace('/__HANDLER__/i', "'".$db->escape($handler)."'", $sql);
|
||||
}
|
||||
|
||||
if (!empty($database)) {
|
||||
$sql = preg_replace('/__DATABASE__/i', "'".$db->escape($database)."'", $sql);
|
||||
}
|
||||
|
||||
$newsql = preg_replace('/__ENTITY__/i', (!empty($entity) ? $entity : $conf->entity), $sql);
|
||||
|
||||
// Add log of request
|
||||
|
||||
@@ -368,6 +368,12 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it
|
||||
*/
|
||||
public $warnings_activation_ext;
|
||||
|
||||
/**
|
||||
* @var array<string,string> Array of warnings to show when we disable the module
|
||||
*
|
||||
* array('always'='text') or array('FR'='text')
|
||||
*/
|
||||
public $warnings_unactivation;
|
||||
|
||||
/**
|
||||
* @var array Minimum version of PHP required by module.
|
||||
|
||||
@@ -100,7 +100,7 @@ class modPrinting extends DolibarrModules
|
||||
$this->rights[$r][4] = 'read';
|
||||
|
||||
// Main menu entries
|
||||
$this->menus = array(); // List of menus to add
|
||||
$this->menu = array(); // List of menus to add
|
||||
$r = 0;
|
||||
|
||||
// This is to declare the Top Menu entry:
|
||||
|
||||
@@ -180,7 +180,7 @@ ALTER TABLE llx_c_paiement DROP INDEX uk_c_paiement;
|
||||
ALTER TABLE llx_c_paiement ADD UNIQUE INDEX uk_c_paiement_code(entity, code);
|
||||
|
||||
-- VMYSQL4.3 ALTER TABLE llx_c_paiement CHANGE COLUMN id id INTEGER AUTO_INCREMENT PRIMARY KEY;
|
||||
-- VPGSQL8.2 CREATE SEQUENCE llx_c_paiement_id_seq OWNED BY llx_c_paiement.id;
|
||||
-- VPGSQL8.2 CREATE SEQUENCE __DATABASE__.llx_c_paiement_id_seq OWNED BY llx_c_paiement.id;
|
||||
-- VPGSQL8.2 ALTER TABLE llx_c_paiement ADD PRIMARY KEY (id);
|
||||
-- VPGSQL8.2 ALTER TABLE llx_c_paiement ALTER COLUMN id SET DEFAULT nextval('llx_c_paiement_id_seq');
|
||||
-- VPGSQL8.2 SELECT setval('llx_c_paiement_id_seq', MAX(id)) FROM llx_c_paiement;
|
||||
@@ -190,7 +190,7 @@ ALTER TABLE llx_c_payment_term DROP INDEX uk_c_payment_term;
|
||||
ALTER TABLE llx_c_payment_term ADD UNIQUE INDEX uk_c_payment_term_code(entity, code);
|
||||
|
||||
-- VMYSQL4.3 ALTER TABLE llx_c_payment_term CHANGE COLUMN rowid rowid INTEGER AUTO_INCREMENT PRIMARY KEY;
|
||||
-- VPGSQL8.2 CREATE SEQUENCE llx_c_payment_term_rowid_seq OWNED BY llx_c_payment_term.rowid;
|
||||
-- VPGSQL8.2 CREATE SEQUENCE __DATABASE__.llx_c_payment_term_rowid_seq OWNED BY llx_c_payment_term.rowid;
|
||||
-- VPGSQL8.2 ALTER TABLE llx_c_payment_term ADD PRIMARY KEY (rowid);
|
||||
-- VPGSQL8.2 ALTER TABLE llx_c_payment_term ALTER COLUMN rowid SET DEFAULT nextval('llx_c_payment_term_rowid_seq');
|
||||
-- VPGSQL8.2 SELECT setval('llx_c_payment_term_rowid_seq', MAX(rowid)) FROM llx_c_payment_term;
|
||||
|
||||
@@ -52,6 +52,7 @@ CREATE OR REPLACE FUNCTION DAY(TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$ S
|
||||
|
||||
CREATE OR REPLACE FUNCTION DAY(DATE) RETURNS INTEGER AS $$ SELECT EXTRACT(DAY FROM $1)::INTEGER; $$ LANGUAGE SQL IMMUTABLE;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION dol_util_rebuild_sequences() RETURNS integer as $body$ DECLARE sequencedefs RECORD; c integer ; BEGIN FOR sequencedefs IN SELECT DISTINCT constraint_column_usage.table_name as tablename, constraint_column_usage.table_name as tablename, constraint_column_usage.column_name as columnname, replace(replace(columns.column_default,'''::regclass)',''),'nextval(''','') as sequencename from information_schema.constraint_column_usage, information_schema.columns, information_schema.sequences where constraint_column_usage.table_schema ='public' AND columns.table_schema = 'public' AND columns.table_name=constraint_column_usage.table_name AND constraint_column_usage.column_name IN ('rowid','id') AND constraint_column_usage.column_name = columns.column_name AND columns.column_default is not null AND replace(replace(columns.column_default,'''::regclass)',''),'nextval(''','')=sequence_name LOOP EXECUTE 'select max('||sequencedefs.columnname||') from ' || sequencedefs.tablename INTO c; IF c is null THEN c = 0; END IF; IF c is not null THEN c = c+ 1; END IF; EXECUTE 'alter sequence ' || sequencedefs.sequencename ||' restart with ' || c; END LOOP; RETURN 1; END; $body$ LANGUAGE plpgsql;
|
||||
-- You can call the function with SELECT dol_util_rebuild_sequences();
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ
|
||||
print '<tr><td class="nowrap">'.$langs->trans("ChoosedMigrateScript").'</td><td class="right">'.$file.'</td></tr>'."\n";
|
||||
|
||||
// Run sql script
|
||||
$ok = run_sql($dir.$file, 0, '', 1, '', 'default', 32768, 0, 0, 2);
|
||||
$ok = run_sql($dir.$file, 0, '', 1, '', 'default', 32768, 0, 0, 2, 0, $db->database_name);
|
||||
$listoffileprocessed[$dir.$file] = $dir.$file;
|
||||
|
||||
|
||||
|
||||
@@ -142,6 +142,13 @@ class PgsqlTest extends PHPUnit\Framework\TestCase
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
/*
|
||||
$sql = "CREATE SEQUENCE __DATABASE__.llx_c_paiement_id_seq OWNED BY llx_c_paiement.id;";
|
||||
$result=DoliDBPgsql::convertSQLFromMysql($sql);
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertEquals($result, "CREATE SEQUENCE __DATABASE__.llx_c_paiement_id_seq OWNED BY llx_c_paiement.id;");
|
||||
*/
|
||||
|
||||
$sql = "ALTER TABLE llx_bank_account MODIFY COLUMN state_id integer USING state_id::integer;";
|
||||
$result=DoliDBPgsql::convertSQLFromMysql($sql);
|
||||
print __METHOD__." result=".$result."\n";
|
||||
|
||||
Reference in New Issue
Block a user