From c120e7b3df34165c538cff0af831872c9d781648 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 19 Dec 2014 16:10:11 +0100 Subject: [PATCH] Clean deprecated files. Add utility tool --- .../emulate_oscommerce/llx_osc_categories.sql | 26 ---- .../llx_osc_customer.key.sql | 20 --- .../emulate_oscommerce/llx_osc_customer.sql | 25 ---- .../emulate_oscommerce/llx_osc_order.sql | 25 ---- .../emulate_oscommerce/llx_osc_product.sql | 27 ---- dev/initdata/sftpget_and_loaddump.php | 138 ++++++++++++++++++ 6 files changed, 138 insertions(+), 123 deletions(-) delete mode 100755 dev/dbmodel/emulate_oscommerce/llx_osc_categories.sql delete mode 100755 dev/dbmodel/emulate_oscommerce/llx_osc_customer.key.sql delete mode 100755 dev/dbmodel/emulate_oscommerce/llx_osc_customer.sql delete mode 100755 dev/dbmodel/emulate_oscommerce/llx_osc_order.sql delete mode 100755 dev/dbmodel/emulate_oscommerce/llx_osc_product.sql create mode 100755 dev/initdata/sftpget_and_loaddump.php diff --git a/dev/dbmodel/emulate_oscommerce/llx_osc_categories.sql b/dev/dbmodel/emulate_oscommerce/llx_osc_categories.sql deleted file mode 100755 index 2fd2820cfd3..00000000000 --- a/dev/dbmodel/emulate_oscommerce/llx_osc_categories.sql +++ /dev/null @@ -1,26 +0,0 @@ --- =================================================================== --- Copyright (C) 2005 Laurent Destailleur --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see . --- --- =================================================================== - -CREATE TABLE llx_osc_categories ( - rowid integer unsigned NOT NULL auto_increment, - dolicatid integer NOT NULL default '0', - osccatid integer NOT NULL default '0', - PRIMARY KEY (rowid), - UNIQUE KEY dolicatid (dolicatid), - UNIQUE KEY osccatid (osccatid) -) ENGINE=InnoDB; diff --git a/dev/dbmodel/emulate_oscommerce/llx_osc_customer.key.sql b/dev/dbmodel/emulate_oscommerce/llx_osc_customer.key.sql deleted file mode 100755 index 002509b4787..00000000000 --- a/dev/dbmodel/emulate_oscommerce/llx_osc_customer.key.sql +++ /dev/null @@ -1,20 +0,0 @@ --- =================================================================== --- Copyright (C) 2005 Laurent Destailleur --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see . --- --- =================================================================== - - -ALTER TABLE llx_osc_customer ADD CONSTRAINT fk_osc_customer_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid); diff --git a/dev/dbmodel/emulate_oscommerce/llx_osc_customer.sql b/dev/dbmodel/emulate_oscommerce/llx_osc_customer.sql deleted file mode 100755 index 895e95e4935..00000000000 --- a/dev/dbmodel/emulate_oscommerce/llx_osc_customer.sql +++ /dev/null @@ -1,25 +0,0 @@ --- =================================================================== --- Copyright (C) 2005 Laurent Destailleur --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see . --- --- =================================================================== - -CREATE TABLE llx_osc_customer ( - rowid integer NOT NULL default '0', - datem datetime default NULL, - fk_soc integer NOT NULL default '0', - PRIMARY KEY (rowid), - UNIQUE KEY fk_soc (fk_soc) -) ENGINE=InnoDB; diff --git a/dev/dbmodel/emulate_oscommerce/llx_osc_order.sql b/dev/dbmodel/emulate_oscommerce/llx_osc_order.sql deleted file mode 100755 index ea1bfbe2c14..00000000000 --- a/dev/dbmodel/emulate_oscommerce/llx_osc_order.sql +++ /dev/null @@ -1,25 +0,0 @@ --- =================================================================== --- Copyright (C) 2005 Laurent Destailleur --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see . --- --- =================================================================== - -CREATE TABLE llx_osc_order ( - rowid integer NOT NULL default '0', - datem datetime default NULL, - fk_commande integer NOT NULL default '0', - PRIMARY KEY (rowid), - UNIQUE KEY fk_commande (fk_commande) -) ENGINE=InnoDB; diff --git a/dev/dbmodel/emulate_oscommerce/llx_osc_product.sql b/dev/dbmodel/emulate_oscommerce/llx_osc_product.sql deleted file mode 100755 index f08db68358d..00000000000 --- a/dev/dbmodel/emulate_oscommerce/llx_osc_product.sql +++ /dev/null @@ -1,27 +0,0 @@ --- =================================================================== --- Copyright (C) 2005 Laurent Destailleur --- --- This program is free software; you can redistribute it and/or modify --- it under the terms of the GNU 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 General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program. If not, see . --- --- =================================================================== - -CREATE TABLE llx_osc_product ( - rowid integer NOT NULL default '0', - datem datetime default NULL, - fk_product integer NOT NULL default '0', - PRIMARY KEY (rowid), - UNIQUE KEY fk_product (fk_product) -) ENGINE=InnoDB; - - diff --git a/dev/initdata/sftpget_and_loaddump.php b/dev/initdata/sftpget_and_loaddump.php new file mode 100755 index 00000000000..c91ddcc3e17 --- /dev/null +++ b/dev/initdata/sftpget_and_loaddump.php @@ -0,0 +1,138 @@ +#!/usr/bin/php + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +$sapi_type = php_sapi_name(); +$script_file = basename(__FILE__); +$path=dirname(__FILE__).'/'; + +// Test if batch mode +if (substr($sapi_type, 0, 3) == 'cgi') { + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit; +} + +// Global variables +$error=0; + +$sourceserver=isset($argv[1])?$argv[1]:''; // user@server:/src/file +$password=isset($argv[2])?$argv[2]:''; +$database=isset($argv[3])?$argv[3]:''; +$loginbase=isset($argv[4])?$argv[4]:''; +$passwordbase=isset($argv[5])?$argv[5]:''; + +// Include Dolibarr environment +$res=0; +if (! $res && file_exists($path."../../master.inc.php")) $res=@include($path."../../master.inc.php"); +if (! $res && file_exists($path."../../htdocs/master.inc.php")) $res=@include($path."../../htdocs/master.inc.php"); +if (! $res && file_exists("../master.inc.php")) $res=@include("../master.inc.php"); +if (! $res && file_exists("../../master.inc.php")) $res=@include("../../master.inc.php"); +if (! $res && file_exists("../../../master.inc.php")) $res=@include("../../../master.inc.php"); +if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include($path."../../../dolibarr".$reg[1]."/htdocs/master.inc.php"); // Used on dev env only +if (! $res && preg_match('/\/nltechno([^\/]*)\//',$_SERVER["PHP_SELF"],$reg)) $res=@include("../../../dolibarr".$reg[1]."/htdocs/master.inc.php"); // Used on dev env only +if (! $res) die ("Failed to include master.inc.php file\n"); +include_once(DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'); + + +/* + * Main + */ + +$login=''; +$server=''; +if (preg_match('/^(.*)@(.*):(.*)$/',$sourceserver,$reg)) +{ + $login=$reg[1]; + $server=$reg[2]; + $sourcefile=$reg[3]; + $targetfile=basename($sourcefile); +} +if (empty($sourceserver) || empty($server) || empty($login) || empty($sourcefile) || empty($password) || empty($database) || empty($loginbase) || empty($passwordbase)) +{ + print "Usage: $script_file login@server:/src/file.(sql|gz|bz2) passssh database loginbase passbase\n"; + print "Return code: 0 if success, <>0 if error\n"; + print "Warning, this script may take a long time.\n"; + exit(-1); +} + + +$targetdir='/tmp'; +print "Get dump file from server ".$server.", path ".$sourcefile.", connect with login ".$login." loaded into localhost\n"; + +$sftpconnectstring=$sourceserver; +print 'SFTP connect string : '.$sftpconnectstring."\n"; +//print 'SFTP password '.$password."\n"; + + +// SFTP connect +if (! function_exists("ssh2_connect")) { + dol_print_error('','ssh2_connect function does not exists'); exit(1); +} + +$connection = ssh2_connect($server, 22); +if ($connection) +{ + if (! @ssh2_auth_password($connection, $login, $password)) + { + dol_syslog("Could not authenticate with username ".$login." . and password ".$password,LOG_ERR); + exit(-5); + } + else + { + //$stream = ssh2_exec($connection, '/usr/bin/php -i'); + /* + print "Generate dump ".$filesys1.'.bz2'."\n"; + $stream = ssh2_exec($connection, "mysqldump -u debian-sys-maint -p4k9Blxl2snq4FHXY -h 127.0.0.1 --single-transaction -K --tables -c -e --hex-blob --default-character-set=utf8 saasplex | bzip2 -1 > ".$filesys1.'.bz2'); + stream_set_blocking($stream, true); + // The command may not finish properly if the stream is not read to end + $output = stream_get_contents($stream); + */ + + $sftp = ssh2_sftp($connection); + + print 'Get file '.$sourcefile.' into '.$targetdir.$targetfile."\n"; + ssh2_scp_recv($connection, $sourcefile, $targetdir.$targetfile); + + $fullcommand="cat ".$targetdir.$targetfile." | mysql -u".$loginbase." -p".$passwordbase." -D ".$database; + if (preg_match('/\.bz2$/',$targetfile)) + { + $fullcommand="bzip2 -c -d ".$targetdir.$targetfile." | mysql -u".$loginbase." -p".$passwordbase." -D ".$database; + } + if (preg_match('/\.gz$/',$targetfile)) + { + $fullcommand="gzip -d ".$targetdir.$targetfile." | mysql -u".$loginbase." -p".$passwordbase." -D ".$database; + } + print "Load dump with ".$fullcommand."\n"; + $output=array(); + $return_var=0; + print strftime("%Y%m%d-%H%M%S").' '.$fullcommand."\n"; + exec($fullcommand, $output, $return_var); + foreach($output as $line) print $line."\n"; + + //ssh2_sftp_unlink($sftp, $fileinstalllock); + //print $output; + } +} +else +{ + print 'Failed to connect to ssh2 to '.$server; + exit(-6); +} + + +exit(0);