migration.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. <?php
  2. //Chemin vers mysqldump.exe, utile sur en environnement windows uniquement
  3. define('MYSQL_DUMP_FILE','C:\Program Files\UwAmp\bin\database\mysql-5.7.11\bin\mysqldump.exe');
  4. define('DUMP_DIRECTORY',__DIR__.DIRECTORY_SEPARATOR.'dumps'.DIRECTORY_SEPARATOR);
  5. if(!file_exists(DUMP_DIRECTORY)){
  6. mkdir(DUMP_DIRECTORY,0755,true);
  7. file_put_contents(DUMP_DIRECTORY.'.htaccess', 'deny for all');
  8. }
  9. require_once(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'common.php');
  10. global $myUser,$lastQuery,$db,$steps;
  11. if(!$myUser->superadmin && (empty($_['token']) || $_['token']!= sha1(CRYPTKEY) ) ) throw new Exception("Permission denied");
  12. ini_set('max_execution_time', 36000);
  13. ob_implicit_flush(true);
  14. ini_set('memory_limit', '2048M');
  15. setlocale( LC_ALL, "fr_FR.utf8" );
  16. /* ACTION NECESSITANT UN CLEAN HEADER*/
  17. if(isset($_['action'])){
  18. switch($_['action']){
  19. case 'download_restore':
  20. $file = DUMP_DIRECTORY.$_['file'];
  21. if(!file_exists($file)) throw new Exception("Le fichier n'existe pas");
  22. if(filesize($file)==0 || filesize($file)<900) throw new Exception("Le fichier est vide ou trop petit, annulation...");
  23. $stream = file_get_contents($file);
  24. ob_end_clean();
  25. header_remove();
  26. header("Content-Type: plain/text");
  27. header("Content-Length: " . strlen($stream));
  28. header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
  29. header('Cache-Control: no-store, no-cache, must-revalidate');
  30. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  31. header('Cache-Control: post-check=0, pre-check=0', FALSE);
  32. header('Pragma: no-cache');
  33. header("Content-Disposition: "."attachment"."; filename=\"".utf8_decode($_['file'])."\"");
  34. echo $stream;
  35. exit();
  36. break;
  37. }
  38. }
  39. /*
  40. Pour autoriser les droits sur la table a un user :
  41. grant_table($base,$table,$user);
  42. ex : grant_table('erp','resource_article','erp-maintenance');
  43. */
  44. //Ne pas supprimer cette étape
  45. addStep('Dump de la base actuelle',function($mode){
  46. mysqldump(BASE_NAME,BASE_LOGIN,BASE_PASSWORD);
  47. });
  48. addStep('Ajout colonne superadmin aux Ranks',function($mode){
  49. Rank::staticQuery('ALTER TABLE `rank` ADD `superadmin` BOOLEAN NOT NULL DEFAULT FALSE AFTER `description`;');
  50. });
  51. global $connected;
  52. $connected = null;
  53. addStep('Création des rangs superadmin',function($mode){
  54. global $connected;
  55. $ranks = array();
  56. foreach(Rank::loadAll() as $rank)
  57. $ranks[$rank->label] = $rank;
  58. info('Rang Super Admin...');
  59. if(!isset($ranks['Super Admin'])){
  60. info('Création du rang Super Admin...');
  61. //create super admin rank
  62. $admin = new Rank();
  63. $admin->label = 'Super Admin';
  64. $admin->description = 'Dispose de tous les accès';
  65. $admin->superadmin = true;
  66. $admin->save();
  67. $admin = $admin;
  68. } else {
  69. info('Rang Super Admin déjà existant...');
  70. $admin = $ranks['Super Admin'];
  71. }
  72. info('Rang Tout le monde - Anonyme...');
  73. if(!isset($ranks['Tout le monde - Anonyme'])){
  74. info('Création du rang Tout le monde - Anonyme...');
  75. //create all anonymous rank
  76. $anonymous = new Rank();
  77. $anonymous->label = 'Tout le monde - Anonyme';
  78. $anonymous->description = 'Utilisateur non connecté à la plateforme';
  79. $anonymous->superadmin = false;
  80. $anonymous->save();
  81. $anonymous = $anonymous;
  82. } else {
  83. info('Rang Tout le monde - Anonyme déjà existant...');
  84. $anonymous = $ranks['Tout le monde - Anonyme'];
  85. }
  86. info('Rang Tout le monde - Connecté...');
  87. if(!isset($ranks['Tout le monde - Connecté'])){
  88. info('Création du rang Tout le monde - Connecté...');
  89. //create all connected rank
  90. $connected = new Rank();
  91. $connected->label = 'Tout le monde - Connecté';
  92. $connected->description = 'Utilisateur connecté à la plateforme';
  93. $connected->superadmin = false;
  94. $connected->save();
  95. $connected = $connected;
  96. } else {
  97. info('Rang Tout le monde - Connecté déjà existant...');
  98. $connected = $ranks['Tout le monde - Connecté'];
  99. }
  100. info('ID du rang "Tout le monde - Connecté" : '.$connected->id);
  101. info('<br><br>Définition des permissions pour CRUD sur ces rangs');
  102. foreach (array($admin,$anonymous,$connected) as $rank) {
  103. info('Permissions uniquement par le SuperAdmin sur le rang : '.$rank->label);
  104. $permission = new Permission;
  105. $permission->scope = 'rank';
  106. $permission->uid = $rank->id;
  107. $permission->read = 1;
  108. $permission->edit = 1;
  109. $permission->delete = 1;
  110. $permission->configure = 1;
  111. $permission->recursive = 1;
  112. $permission->targetScope = 'rank';
  113. $permission->targetUid = $admin->id;
  114. $permission->save();
  115. }
  116. });
  117. addStep('Ajout visibilité par défaut aux utilisateurs connectés pour les menus',function($mode) {
  118. global $connected, $conf;
  119. if(empty($connected)){
  120. info('Aucun identfiaint de rank Tout le monde - Connecté, annulation...');
  121. return;
  122. }
  123. info('<strong class="text-danger">Attention, spécifier le rang en configuration du plugin Menus & Navigation !!!</strong>');
  124. Plugin::need('navigation/MenuItem');
  125. foreach(MenuItem::staticQuery('SELECT * FROM {{table}} WHERE visibility IS NULL OR visibility = ""', array(), true) as $menu){
  126. info('Menu : <strong>'.$menu->label.'</strong>');
  127. $menu->visibility = $connected->id;
  128. $menu->save();
  129. }
  130. $conf->put('default_menu_visibility', $connected->id);
  131. });
  132. addStep('Migration des users Super Admin avec le rang Super Admin',function($mode){
  133. foreach(User::getAll() as $user){
  134. if(!isset($user->superadmin) || empty($user->superadmin)) continue;
  135. info('<strong class="text-danger">User en Super Admin : '.$user->login.'</strong>');
  136. $superAdminRank = Rank::load(array('superadmin'=>true));
  137. $ufrs = array();
  138. foreach(UserFirmRank::loadAll(array('user'=>$user->login, 'rank'=>$superAdminRank->id)) as $ufr)
  139. $ufrs[$ufr->firm] = $ufr;
  140. foreach(Firm::loadAll() as $firm){
  141. if(isset($ufrs[$firm->id])) continue;
  142. info('Création du lien UFR pour le combo UFR : '.$user->login.'/'.$firm->label.'/'.$superAdminRank->label);
  143. $newUfr = new UserFirmRank;
  144. $newUfr->firm = $firm->id;
  145. $newUfr->user = $user->login;
  146. $newUfr->rank = $superAdminRank->id;
  147. $newUfr->save();
  148. }
  149. }
  150. });
  151. addStep('Suppression de la colonne superadmin de la table user',function($mode){
  152. User::staticQuery('ALTER TABLE {{table}} DROP COLUMN superadmin;');
  153. });
  154. addStep('Client : ajout du champs pseudonyme',function($mode){
  155. User::staticQuery('ALTER TABLE `client` ADD `pseudonym` VARCHAR(225) NULL AFTER `label`;');
  156. });
  157. addStep('Contacts personne : ajout du champs commentaire',function($mode){
  158. ContactPerson::staticQuery('ALTER TABLE {{table}} ADD `comment` TEXT NULL AFTER `state`;');
  159. });
  160. addStep('Stats : alteration table vers nouveau système de connexion <span class="text-warning">(ne fonctionne que pour mysql)</span>', function(){
  161. info('Déplacement ancienne table connexion');
  162. move_table('statistic_connection','statistic_connection_old');
  163. info('Création nouvelle table connexion');
  164. Plugin::need('statistic/Connection');
  165. Connection::create();
  166. info('Migration des connexions');
  167. foreach (Connection::staticQuery('SELECT * FROM statistic_connection_old')->fetchAll() as $value) {
  168. $connection = new Connection();
  169. $connection->label = $value['label'];
  170. $connection->handler = 'Mysql';
  171. $json = array();
  172. $json["host"] = $value['host'];
  173. $json["login"] = $value['login'];
  174. $json["password"] = $value['password'];
  175. $json["name"] = $value['database'];
  176. $connection->meta = json_encode($json);
  177. $connection->save();
  178. }
  179. });
  180. addStep('Business : Ajout colonne qualification',function($mode){
  181. Rank::staticQuery('ALTER TABLE `business` ADD `qualification` INT(3) NULL AFTER `description`;');
  182. info('Migration des affaires existantes');
  183. Rank::staticQuery("UPDATE business SET qualification = 10 WHERE step IN ('approved','checked','draft','opportunity')");
  184. Rank::staticQuery("UPDATE business SET qualification = 60 WHERE step IN ('client_waiting')");
  185. Rank::staticQuery("UPDATE business SET qualification = 100 WHERE step IN ('invoiced','ordered_client','paid','ready','supplier_waiting','to_invoice','to_prepare','ordered_provider')");
  186. });
  187. addStep('Stats : Ajout colonne meta', function($mode){
  188. User::staticQuery('ALTER TABLE `statistic_widget` ADD `meta` TEXT NULL AFTER `creator`;');
  189. });
  190. addStep('Tickets : Changement structure table pour colonne "from"', function($mode){
  191. Plugin::need('issue/IssueReport');
  192. IssueReport::staticQuery('ALTER TABLE `issue_report` CHANGE `from` `from` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;');
  193. });
  194. addStep('Contact person : Ajout d\'une colonne tag',function($mode){
  195. User::staticQuery('ALTER TABLE contact_person ADD `tag` TEXT NULL AFTER `uid`;');
  196. });
  197. addStep('Contacts personne : ajout du champs type',function($mode){
  198. ContactPerson::staticQuery('ALTER TABLE {{table}} ADD `type` VARCHAR(225) NULL AFTER `state`;');
  199. ContactPerson::staticQuery('UPDATE {{table}} SET `type`= "user" WHERE account IS NOT NULL AND account !=""');
  200. });
  201. addStep('DynamicForm : ajout du champs firm',function($mode){
  202. Plugin::need('dynamicform/DynamicForm');
  203. DynamicForm::staticQuery('ALTER TABLE {{table}} ADD `firm` INT(11) NULL AFTER `state`;');
  204. DynamicForm::staticQuery('UPDATE {{table}} SET `firm`= 0 ');
  205. });
  206. addStep('Firm : Déplacement des logos dans le rep public', function(){
  207. $source = File::dir().'core'.SLASH.'firm';
  208. $destination = File::dir().'core'.SLASH.'public'.SLASH.'firm';
  209. if(!is_dir($source)) throw new Exception("Dossier source inexistant");
  210. File::copy($source, $destination);
  211. });
  212. addStep('Droits : fusion permission et droits ', function(){
  213. global $myFirm;
  214. info('Création des colonnes targetScope,uid,recursive');
  215. Right::staticQuery('ALTER TABLE {{table}} ADD `targetScope` VARCHAR(225) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;');
  216. Right::staticQuery('ALTER TABLE {{table}} ADD `uid` INT(11) NULL AFTER `firm`;');
  217. Right::staticQuery('ALTER TABLE {{table}} ADD `recursive` INT(11) NULL AFTER `firm`;');
  218. info('Migrations des colonnes section-> scope, rank->targetUid');
  219. Right::staticQuery('ALTER TABLE {{table}} CHANGE `section` `scope` VARCHAR(225) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;');
  220. Right::staticQuery('ALTER TABLE {{table}} CHANGE `rank` `targetUid` VARCHAR(225) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;');
  221. info('Fill des targetScope en "rank"');
  222. Right::staticQuery('UPDATE {{table}} SET targetScope = "rank"');
  223. info('Fill des uid en 0');
  224. Right::staticQuery('UPDATE {{table}} SET uid = 0');
  225. info('Migration de la table permission dans la table right');
  226. $oldPermissions = Right::staticQuery('SELECT * FROM permission',array())->fetchAll();
  227. foreach($oldPermissions as $oldPermission){
  228. $right = new Right();
  229. $right->firm = $myFirm->id;
  230. $right->read = $oldPermission['read'];
  231. $right->edit = $oldPermission['edit'];
  232. $right->delete = $oldPermission['delete'];
  233. $right->configure = $oldPermission['configure'];
  234. $right->scope = $oldPermission['scope'];
  235. $right->uid = $oldPermission['uid'];
  236. $right->targetScope = $oldPermission['targetScope'];
  237. $right->targetUid = $oldPermission['targetUid'];
  238. $right->recursive = $oldPermission['recursive'];
  239. $right->save();
  240. }
  241. info('Suppression de la table de permissions');
  242. //Right::staticQuery('DROP TABLE IF EXISTS permission');
  243. });
  244. addStep('Client : ajout du champs firm',function($mode){
  245. Plugin::need('client/Client');
  246. Client::staticQuery('ALTER TABLE {{table}} ADD `firm` INT(11) NULL AFTER `state`;');
  247. Client::staticQuery('UPDATE {{table}} SET `firm`= 0 ');
  248. });
  249. addStep('Navigation : ajout du champs firm',function($mode){
  250. Plugin::need('navigation/MenuItem');
  251. MenuItem::staticQuery('ALTER TABLE {{table}} ADD `firm` INT(11) NULL AFTER `sort`;');
  252. MenuItem::staticQuery('UPDATE {{table}} SET `firm`= 0 ');
  253. });
  254. addStep('Tickets : Changement structure table pour colonne "from"', function($mode){
  255. Plugin::need('issue/IssueReport');
  256. IssueReport::staticQuery('ALTER TABLE `issue_report` CHANGE `from` `from` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;');
  257. });
  258. addStep('Summary : Ajout de la configuration', function(){
  259. global $conf;
  260. $conf->put('summary_files_extension', 'jpg,png,svg,bmp,gif,jpeg,doc,xls,ppt,docx,xlsx,pptx,pdf,msg,eml,txt');
  261. });
  262. addStep('Stats : modification statistic en statistic_widget', function($mode){
  263. User::staticQuery('UPDATE `right` SET scope="statistic_widget" WHERE scope="statistic";');
  264. });
  265. addStep('User : Ajout colonne meta', function(){
  266. User::staticQuery('ALTER TABLE `user` ADD `meta` TEXT NULL AFTER `origin`;');
  267. });
  268. /** SCRIPT DE MIGRATION ICI **/
  269. /*
  270. addStep('',function($mode){
  271. });
  272. */
  273. addStep('Changement interclassement des tables et colonnes en utf8_general_ci',function($mode){
  274. global $databases_credentials;
  275. $dbConstant = $databases_credentials['local'];
  276. info("Récupération des requêtes à passer...");
  277. $query = '
  278. SELECT CONCAT("ALTER DATABASE `",TABLE_SCHEMA,"` CHARACTER SET = utf8 COLLATE = utf8_general_ci;") AS query
  279. FROM `TABLES` WHERE TABLE_SCHEMA LIKE "'.$dbConstant['name'].'" AND TABLE_TYPE=\'BASE TABLE\' GROUP BY TABLE_SCHEMA UNION
  280. SELECT CONCAT("ALTER TABLE `",TABLE_SCHEMA,"`.`",table_name,"` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;") AS query
  281. FROM `TABLES` WHERE TABLE_SCHEMA LIKE "'.$dbConstant['name'].'" AND TABLE_TYPE=\'BASE TABLE\' GROUP BY TABLE_SCHEMA, table_name UNION
  282. SELECT CONCAT("ALTER TABLE `",`COLUMNS`.TABLE_SCHEMA,"`.`",`COLUMNS`.table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type,"(",character_maximum_length,") CHARACTER SET utf8 COLLATE utf8_general_ci",IF(is_nullable="YES"," NULL"," NOT NULL"),";") AS query
  283. FROM `COLUMNS` INNER JOIN `TABLES` ON `TABLES`.table_name = `COLUMNS`.table_name WHERE `COLUMNS`.TABLE_SCHEMA like "'.$dbConstant['name'].'" and data_type in (\'varchar\',\'char\') AND TABLE_TYPE=\'BASE TABLE\' UNION
  284. SELECT CONCAT("ALTER TABLE `",`COLUMNS`.TABLE_SCHEMA,"`.`",`COLUMNS`.table_name, "` CHANGE `",column_name,"` `",column_name,"` ",data_type," CHARACTER SET utf8 COLLATE utf8_general_ci",IF(is_nullable="YES"," NULL"," NOT NULL"),";") AS query
  285. FROM `COLUMNS` INNER JOIN `TABLES` ON `TABLES`.table_name = `COLUMNS`.table_name WHERE `COLUMNS`.TABLE_SCHEMA like "'.$dbConstant['name'].'" and data_type in (\'text\',\'tinytext\',\'mediumtext\',\'longtext\') AND TABLE_TYPE=\'BASE TABLE\';';
  286. $result = array();
  287. $pdo = new PDO('mysql:host='.$dbConstant['host'].';dbname=information_schema', $dbConstant['login'], $dbConstant['password']);
  288. foreach($pdo->query($query)->fetchAll(PDO::FETCH_ASSOC) as $qry){
  289. preg_match("/ALTER TABLE `".$dbConstant['name']."`\.`(.*)`/iU", $qry['query'], $matches);
  290. if(!empty($matches)) $result[$matches[1]][] = $qry['query'];
  291. else $result['database'][] = $qry['query'];
  292. }
  293. info("<i><strong>Disclaimer (avant d'afficher toutes les requêtes) : c'est un peu long quand tu vas l'executer dans ton PMA :D</strong></i>");
  294. $allQueries = '';
  295. foreach ($result as $scope => $queries) {
  296. info('Requêtes pour <strong class="text-primary">'.$scope.'</strong> :');
  297. $currentQueries = '';
  298. foreach($queries as $qry)
  299. $currentQueries .= $qry.PHP_EOL;
  300. info('<br><code class="pointer" onclick="copy_string(\''.str_replace(PHP_EOL, '', $currentQueries).'\', this)">'.nl2br($currentQueries).'</code>');
  301. $allQueries .= $currentQueries;
  302. }
  303. info('<br><strong class="text-primary">Toutes les requêtes en UN</strong><br><code class="pointer" onclick="copy_string(\''.str_replace(PHP_EOL, '', $allQueries).'\', this)">'.nl2br($allQueries).'</code>');
  304. });
  305. addStep('Employee : Ajout colonne state.', function($mode){
  306. Plugin::need('employee/Employee');
  307. Employee::staticQuery('ALTER TABLE {{table}} ADD `state` VARCHAR(225) NULL AFTER `comment`;');
  308. Employee::staticQuery('UPDATE {{table}} SET state = "'.Employee::ACTIVE.'";');
  309. });
  310. addStep('Dictionary : Correctif de la faute historique', function($mode){
  311. Dictionary::staticQuery('RENAME TABLE `dictionnary` TO {{table}};');
  312. });
  313. addStep('Host : input client en dynamicForm', function($mode){
  314. Plugin::need('dynamicform/DynamicForm, dynamicform/DynamicField, dynamicform/DynamicValue, host/Machine, client/Client');
  315. $form = DynamicForm::load(array('slug'=>'host-sheet'));
  316. if($form)return;
  317. $form = new DynamicForm();
  318. $form->slug = 'host-sheet';
  319. $form->label = 'Fiche hébergement';
  320. $form->state = 'published';
  321. $form->creator = 'admin';
  322. $form->updater = 'admin';
  323. $form->firm = 1;
  324. $form->save();
  325. $field = DynamicField::load(array('slug'=>'host-sheet-client'));
  326. if($field)return;
  327. $clientField = new DynamicField();
  328. $clientField->slug = $form->slug . '-client';
  329. $clientField->type = 'client';
  330. $clientField->label = 'Client';
  331. $clientField->state = 'published';
  332. $clientField->creator = 'admin';
  333. $clientField->form = $form->id;
  334. $clientField->mandatory = 0;
  335. $clientField->readonly = 0;
  336. $clientField->row = 0;
  337. $clientField->sort = 0;
  338. $clientField->column = 0;
  339. $clientField->save();
  340. foreach(Machine::loadAll() as $machine)
  341. {
  342. if(empty($machine->client))continue;
  343. $client = Client::getById($machine->client);
  344. $clientName = $client ? $client->label : null;
  345. $clientValue = new DynamicValue();
  346. $clientValue->field = $clientField->id;
  347. $clientValue->value = $machine->client;
  348. $clientValue->firm = 1;
  349. $clientValue->scope = 'host';
  350. $clientValue->uid = $machine->id;
  351. $clientValue->creator = 'admin';
  352. $clientValue->save();
  353. }
  354. });
  355. addStep('Plugin : Migration enabled.json vers /file/core/plugin.json', function($mode){
  356. rename(__ROOT__.PLUGIN_PATH.'enabled.json',File::core().SLASH.'plugin.json');
  357. });
  358. /** FIN DU SCRIPT **/
  359. /******************************************************/
  360. /** NE PAS ALLER PLUS LOIN * */
  361. /** Sauf pour modifier le script sandpiper lui même **/
  362. /******************************************************/
  363. ?>
  364. <!DOCTYPE html>
  365. <html lang="fr">
  366. <head>
  367. <meta charset="utf-8">
  368. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  369. <meta name="description" content="">
  370. <meta name="author" content="">
  371. <link rel="icon" type="image/png" href="favicon.png" />
  372. <title>Sandpiper</title>
  373. <!-- Bootstrap core CSS -->
  374. <link href="../css/bootstrap.min.css" rel="stylesheet">
  375. <!-- Jquery ui -->
  376. <link rel="stylesheet" href="../css/jquery-ui.min.css">
  377. <!-- Font awesome -->
  378. <link rel="stylesheet" href="../css/fontawesome-all.min.css">
  379. <!-- Lato font-->
  380. <?php if(!$conf->get('offline_mode')): ?>
  381. <link href="https://fonts.googleapis.com/css?family=Lato:300,400" rel="stylesheet">
  382. <?php endif; ?>
  383. <!-- Custom styles for this template -->
  384. <link href="../css/main.css" rel="stylesheet">
  385. <style>
  386. .logo path:nth-child(3){
  387. animation: fly2 linear 1s;
  388. animation-iteration-count: infinite;
  389. transform-origin: 50% 50%;
  390. }
  391. .logo path:nth-child(2){
  392. animation: fly1 linear 2.5s;
  393. animation-iteration-count: infinite;
  394. transform-origin: 50% 50%;
  395. }
  396. .logo path:nth-child(4){
  397. animation: fly1 linear 2s;
  398. animation-iteration-count: infinite;
  399. transform-origin: 50% 50%;
  400. }
  401. .logo path:nth-child(1){
  402. animation: fly2 linear 3s;
  403. animation-iteration-count: infinite;
  404. transform-origin: 50% 50%;
  405. }
  406. @keyframes fly1{
  407. 0% {
  408. transform: translate(0px,0px) ;
  409. }
  410. 50% {
  411. transform: translate(7px,-13px) ;
  412. }
  413. 100% {
  414. transform: translate(0px,0px) ;
  415. }
  416. }
  417. @keyframes fly2{
  418. 0% {
  419. transform: translate(0px,0px) ;
  420. }
  421. 50% {
  422. transform: translate(10px,13px) ;
  423. }
  424. 100% {
  425. transform: translate(0px,0px) ;
  426. }
  427. }
  428. .navbar-brand span{
  429. font-weight: bold;
  430. }
  431. .card-img-top{
  432. padding:15px;
  433. text-align: center;
  434. }
  435. .card-img-top svg{
  436. margin: auto;
  437. }
  438. </style>
  439. </head>
  440. <body>
  441. <nav class="navbar navbar-dark bg-primary">
  442. <a class="navbar-brand" href="migration.php">
  443. <svg class="logo mr-3" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 303.327 303.327" style="enable-background:new 0 0 303.327 303.327;" xml:space="preserve" width="52px" height="52px"><g><g>
  444. <path d="M172.631,211.084c-17.389-3.674-34.588-0.419-48.851,7.808c-9.732-13.297-24.135-23.235-41.523-26.908 c-37.423-7.912-74.2,16.02-82.111,53.458c-0.031,0.144-0.06,0.289-0.09,0.433c-0.259,1.244,0.397,2.503,1.563,3.015 c1.165,0.514,2.528,0.146,3.274-0.885c14.909-20.499,41.285-25.346,69.611-19.359c17.388,3.674,31.8,13.616,41.524,26.908 c14.263-8.221,31.472-11.48,48.859-7.809c28.326,5.982,50.472,21.086,55.826,45.858c0.269,1.245,1.363,2.13,2.638,2.135 c1.274,0.006,2.368-0.88,2.646-2.119c0.031-0.145,0.06-0.283,0.09-0.423C234.001,255.753,210.054,218.99,172.631,211.084z" data-original="#000000" class="active-path" data-old_color="#FCF6F6" fill="#FFFFFF"/>
  445. <path d="M269.374,142.83c-13.557-6.32-28.276-6.917-41.544-2.886c-5.453-12.75-15.368-23.639-28.924-29.959 c-29.191-13.605-63.897-0.97-77.504,28.222c0,0-0.009,0.009-0.009,0.02c-0.469,1-0.169,2.195,0.717,2.861 c0.875,0.667,2.109,0.632,2.945-0.085c16.103-13.755,38.538-12.675,60.523-2.429c13.557,6.321,23.479,17.209,28.924,29.96 c13.258-4.033,27.988-3.435,41.545,2.881c22.424,10.455,37.841,27.391,37.024,49.188c-0.029,0.971,0.616,1.831,1.553,2.075 c0.945,0.238,1.921-0.214,2.349-1.08c0.209-0.423,0.418-0.847,0.616-1.273C311.196,191.132,298.556,156.431,269.374,142.83z" data-original="#000000" class="active-path" data-old_color="#FCF6F6" fill="#FFFFFF"/>
  446. <path d="M94.51,37.677c0.606,0.254,1.313,0.05,1.702-0.492c7.256-10.366,20.402-13.103,34.655-10.466 c8.789,1.622,16.164,6.439,21.22,13.003c7.066-4.324,15.686-6.186,24.484-4.559c14.253,2.633,25.539,9.888,28.625,22.165 c0.159,0.643,0.747,1.086,1.403,1.06c0.657-0.019,1.215-0.497,1.334-1.149c3.503-18.931-9.008-37.12-27.939-40.618 c-8.798-1.623-17.407,0.233-24.475,4.558c-5.056-6.564-12.441-11.381-21.229-13.003c-18.941-3.499-37.125,9.012-40.629,27.948 C93.544,36.776,93.892,37.424,94.51,37.677z" data-original="#000000" class="active-path" data-old_color="#FCF6F6" fill="#FFFFFF"/>
  447. <path d="M258.933,35.328c5.025,4.519,7.872,10.541,8.54,16.771c6.259,0.005,12.559,2.215,17.596,6.739 c8.48,7.628,12.909,17.223,9.296,26.728c-0.139,0.354,0,0.752,0.309,0.956c0.319,0.204,0.737,0.159,1.006-0.11 c0.298-0.302,0.597-0.616,0.886-0.939c9.733-10.825,8.858-27.496-1.971-37.24c-5.027-4.523-11.316-6.728-17.577-6.733 c-0.666-6.225-3.533-12.251-8.55-16.776c-10.828-9.744-27.5-8.863-37.244,1.961c-0.338,0.383-0.367,0.936-0.069,1.343 c0.288,0.403,0.825,0.547,1.284,0.349C241.216,24.564,250.782,27.998,258.933,35.328z" data-original="#000000" class="active-path" data-old_color="#FCF6F6" fill="#FFFFFF"/>
  448. </g></g> </svg>
  449. SAND<span>P|PE</span>R</a>
  450. </nav>
  451. <!-- Begin page content -->
  452. <div class="container-fluid pt-2">
  453. <?php
  454. try{
  455. if(isset($_['action'])){
  456. switch($_['action']){
  457. case 'restore':
  458. title("Restauration");
  459. $file = DUMP_DIRECTORY.$_['file'];
  460. info("Restauration du fichier <code>$file</code>");
  461. if(!file_exists($file)) throw new Exception("Le fichier n'existe pas");
  462. if(filesize($file)==0 || filesize($file)<900) throw new Exception("Le fichier est vide ou trop petit, annulation...");
  463. mysqlrestore(BASE_NAME,BASE_LOGIN,BASE_PASSWORD,$file);
  464. info("Restauration terminée");
  465. info("<a href='migration.php'>Revenir au menu</a>");
  466. break;
  467. case 'download_restore':
  468. title("Téléchargement");
  469. $file = DUMP_DIRECTORY.$_['file'];
  470. info("Téléchargement du fichier <code>$file</code>");
  471. if(!file_exists($file)) throw new Exception("Le fichier n'existe pas");
  472. if(filesize($file)==0 || filesize($file)<900) throw new Exception("Le fichier est vide ou trop petit, annulation...");
  473. info("nope, ça download pas encore pour le moment ¯\_(ツ)_/¯");
  474. // File::downloadFile($file);
  475. info("Téléchargement terminé");
  476. info("<a href='migration.php'>Revenir au menu</a>");
  477. break;
  478. case 'delete_restore':
  479. title("Supression de point de restauration");
  480. $file = DUMP_DIRECTORY.$_['file'];
  481. info("Suppression de la restauration <code>$file</code>");
  482. if(!file_exists($file)) throw new Exception("Le fichier n'existe pas");
  483. unlink($file);
  484. info("Suppression terminée");
  485. info("<a href='migration.php'>Revenir au menu</a>");
  486. break;
  487. case 'migrate':
  488. if(!$myUser->superadmin) throw new Exception("Vous n'avez pas la permission de lancer cette action");
  489. if(!isset($_['steps']) || count($_['steps'])==0) throw new Exception("Aucune étape renseignée, impossible de lancer.");
  490. $time_start = microtime(true);
  491. title('Lancement de la migration');
  492. info("Mode : ".$_['mode']);
  493. foreach ($steps as $slug => $step) {
  494. if(!isset($_['steps'][$slug]) || $_['steps'][$slug]!='on' ) continue;
  495. title('> '.$step['label']);
  496. $callback = $step['callback'];
  497. $callback($_['mode']);
  498. execution_time($time_start);
  499. }
  500. title('Migration terminée');
  501. execution_time($time_start);
  502. info("<a href='migration.php'>Revenir au menu</a>");
  503. break;
  504. }
  505. }else{
  506. ?>
  507. <div class="row justify-content-md-center">
  508. <div class="col-md-4">
  509. <div class="card w-100" >
  510. <div class="card-img-top bg-danger" >
  511. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 531.921 531.921" style="enable-background:new 0 0 531.921 531.921;" xml:space="preserve" class=""><g><g>
  512. <path d="M13.01,253.731L158.187,6.44c2.32-3.972,6.797-6.44,11.694-6.44c4.885,0,9.363,2.468,11.683,6.434l98.629,167.989 l-13.645,7.105L188.42,43.737c-2.825-4.8-8.26-7.439-13.781-6.659c-5.509,0.769-10.025,4.788-11.423,10.181L109.24,265.813 c-1.052,3.623-0.567,7.524,1.339,10.775c1.912,3.263,5.071,5.598,8.745,6.466c17.389,4.067,35.334,6.136,53.347,6.136l0,0 c1.848,0,3.674-0.035,5.485-0.071l0.083,17.579c-3.877,0.142-7.788,0.236-11.76,0.236h-0.023 c-52.278,0-102.188-12.282-148.325-36.517c-3.147-1.655-5.382-4.339-6.301-7.589C10.953,259.754,11.381,256.521,13.01,253.731z M200.567,251.409c0.012-2.506,1.431-4.803,3.662-5.926l152.438-79.467c1.75-0.877,3.783-0.943,5.586-0.186l154.218,74.688 c0.13,0.062,0.236,0.153,0.372,0.225c0.148,0.074,0.319,0.109,0.455,0.201c0.154,0.083,0.272,0.21,0.414,0.319 c0.225,0.151,0.426,0.31,0.627,0.497c0.248,0.225,0.461,0.461,0.674,0.721c0.165,0.198,0.319,0.399,0.461,0.63 c0.189,0.283,0.331,0.594,0.461,0.896c0.106,0.236,0.213,0.461,0.283,0.694c0.106,0.357,0.154,0.709,0.213,1.079 c0.024,0.189,0.095,0.37,0.106,0.556c0,0.05-0.023,0.098-0.012,0.142c0,0.059,0.012,0.118,0.012,0.174v197.443 c0,2.441-1.336,4.688-3.487,5.863l-149.654,81.161c-0.976,0.532-2.069,0.804-3.15,0.804c-1.183,0-2.364-0.319-3.417-0.945 c-0.603-0.367-1.123-0.84-1.572-1.359h-0.018c-1.094,0-2.175-0.272-3.15-0.793L204.51,449.449c-2.143-1.141-3.488-3.398-3.5-5.828 l-0.89-189.768c0-0.816,0.186-1.599,0.473-2.344C200.594,251.473,200.567,251.444,200.567,251.409z M370.895,514.107 l136.332-73.985V257.81l-136.332,76.195V514.107z M364.162,322.515l134.346-75.126l-138.59-68.092l-138.022,72.206L364.162,322.515 z M121.558,468.262c3.559,1.963,7.256,3.807,11.065,5.532l-6.218,1.797c-2.329,0.674-4.256,2.211-5.423,4.339 s-1.439,4.581-0.769,6.916c1.351,4.651,6.585,7.542,11.239,6.188l30.142-8.73c2.332-0.674,4.268-2.211,5.435-4.338 c1.159-2.129,1.431-4.581,0.757-6.904l-8.722-30.156c-1.348-4.658-6.584-7.543-11.239-6.195c-2.329,0.674-4.256,2.223-5.423,4.345 c-1.167,2.134-1.439,4.581-0.769,6.91l3.298,11.396c-5.095-2.074-9.998-4.403-14.611-6.939 C58.732,412.985,64.735,328.16,64.809,327.302c0.295-3.558-1.537-6.975-4.667-8.7c-1.126-0.627-2.355-0.993-3.632-1.1 c-4.962-0.413-9.375,3.304-9.788,8.287C46.633,326.759,39.848,423.246,121.558,468.262z" data-original="#000000" class="active-path" data-old_color="#F8F7F7" fill="#FFFFFF"/>
  513. </g></g> </svg>
  514. </div>
  515. <div class="card-body">
  516. <form action="migration.php" method="GET">
  517. <h5 class="card-title">Migration</h5>
  518. <p class="card-text">Lancer une migration complete avec les étapes :
  519. <ol>
  520. <?php foreach($steps as $slug=>$step): ?>
  521. <li><label><input data-type="checkbox" name="steps[<?php echo $slug ?>]"> <?php echo $step['label']; ?></label></li>
  522. <?php endforeach; ?>
  523. </ol>
  524. </p>
  525. <h5>Mode</h5>
  526. <label><input data-type="radio" type="radio" name="mode" checked="checked" value="debug">Debug </label>
  527. <label><input data-type="radio" type="radio" name="mode" value="production">Production</label>
  528. <input type="hidden" name="action" value="migrate">
  529. <div onclick="$(this).closest('form').submit()" class="btn btn-primary w-100">Go !</div>
  530. </form>
  531. </div>
  532. </div>
  533. </div>
  534. <div class="col-md-4">
  535. <div class="card w-100" >
  536. <div class="card-img-top bg-dark" >
  537. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 87.883 87.883" style="enable-background:new 0 0 87.883 87.883;" xml:space="preserve" class=""><g><g>
  538. <path d="M2.149,41.921L26.134,1.064C26.517,0.408,27.258,0,28.065,0s1.548,0.408,1.93,1.063l16.294,27.756l-2.253,1.174 L31.128,7.226c-0.467-0.793-1.365-1.229-2.276-1.1c-0.911,0.127-1.656,0.791-1.887,1.682l-8.917,36.109 c-0.174,0.599-0.094,1.243,0.221,1.78c0.315,0.539,0.837,0.925,1.445,1.068c2.873,0.672,5.839,1.014,8.814,1.014h0.001 c0.305,0,0.606-0.006,0.906-0.012l0.014,2.904c-0.641,0.023-1.287,0.039-1.944,0.039h-0.003c-8.638,0-16.882-2.029-24.507-6.033 c-0.518-0.273-0.888-0.717-1.04-1.254C1.808,42.916,1.878,42.382,2.149,41.921z M33.137,41.537 c0.002-0.414,0.235-0.793,0.605-0.979l25.186-13.129c0.289-0.145,0.625-0.156,0.923-0.031l25.48,12.34 c0.021,0.01,0.038,0.025,0.061,0.037c0.024,0.012,0.052,0.018,0.075,0.033c0.025,0.014,0.044,0.035,0.068,0.053 c0.037,0.025,0.071,0.051,0.104,0.082c0.041,0.037,0.077,0.076,0.111,0.119c0.027,0.033,0.054,0.066,0.078,0.104 c0.03,0.047,0.053,0.098,0.076,0.148c0.017,0.039,0.035,0.076,0.047,0.115c0.018,0.059,0.025,0.117,0.034,0.178 c0.004,0.031,0.016,0.061,0.017,0.092c0,0.008-0.002,0.016-0.002,0.023c0,0.01,0.003,0.02,0.003,0.029v32.621 c0,0.403-0.222,0.774-0.577,0.969L60.7,87.75c-0.163,0.088-0.343,0.133-0.523,0.133c-0.194,0-0.39-0.053-0.562-0.156 c-0.102-0.061-0.187-0.139-0.261-0.225c0,0-0.001,0-0.002,0c-0.18,0-0.358-0.045-0.521-0.131L33.787,74.257 c-0.354-0.188-0.576-0.562-0.579-0.963l-0.145-31.353c0-0.135,0.032-0.264,0.078-0.387C33.14,41.548,33.137,41.543,33.137,41.537z M61.276,84.939l22.526-12.224V42.595L61.276,55.184V84.939z M60.164,53.285l22.197-12.412l-22.898-11.25l-22.804,11.93 L60.164,53.285z M47.608,12.025c0,0.4,0.156,0.777,0.438,1.061l3.667,3.667c0.566,0.566,1.556,0.566,2.121,0 c0.283-0.283,0.439-0.66,0.439-1.061s-0.156-0.777-0.439-1.061l-1.386-1.386c0.903-0.106,1.796-0.16,2.668-0.16 c13.504,0,19.396,12.754,19.454,12.883c0.241,0.539,0.779,0.888,1.37,0.888c0.213,0,0.419-0.044,0.611-0.131 c0.754-0.337,1.095-1.226,0.758-1.98c-0.066-0.148-6.776-14.652-22.19-14.652c-0.671,0-1.354,0.028-2.042,0.083l0.757-0.757 c0.283-0.283,0.439-0.66,0.439-1.061s-0.156-0.777-0.439-1.061c-0.565-0.566-1.555-0.566-2.121,0l-3.667,3.667 C47.765,11.248,47.608,11.625,47.608,12.025z" data-original="#000000" class="active-path" data-old_color="#000000" fill="#FFFFFF"/>
  539. </g></g> </svg>
  540. </div>
  541. <div class="card-body">
  542. <h5 class="card-title">Restauration</h5>
  543. <p class="card-text">
  544. <?php
  545. $dumps = glob(DUMP_DIRECTORY.'*.sql');
  546. if(count($dumps)==0): ?>
  547. <small class="text-muted"><i class="far fa-grimace"></i> Aucune restauration disponible, essayez de rafraichir la page</small>
  548. <?php else: ?>
  549. Restaurer une des sauvegardes suivantes :
  550. <ol>
  551. <?php foreach($dumps as $dump): ?>
  552. <li class="p-1">
  553. <span><?php echo str_replace(array('.sql','_'),array('',' '),basename($dump)); ?> <small class="text-muted">(<?php echo readable_size(filesize($dump)); ?>)</small></span>
  554. <a title="Restaurer" href="migration.php?action=restore&file=<?php echo basename($dump); ?>" class="btn btn-sm d-inline-block btn-success ml-2">
  555. <i class="fas fa-redo-alt"></i>
  556. </a>
  557. <a title="Télécharger" href="migration.php?action=download_restore&file=<?php echo basename($dump); ?>" class="btn btn-sm d-inline-block btn-primary ml-1">
  558. <i class="fas fa-download"></i>
  559. </a>
  560. <a title="Supprimer" href="migration.php?action=delete_restore&file=<?php echo basename($dump); ?>" class="btn btn-sm d-inline-block btn-danger ml-1">
  561. <i class="fas fa-trash-alt"></i>
  562. </a>
  563. </li>
  564. <?php endforeach; ?>
  565. </ol>
  566. <?php endif; ?>
  567. </p>
  568. </div>
  569. </div>
  570. </div>
  571. </div>
  572. <?php
  573. }
  574. }catch(PdoException $e){
  575. error($e->getMessage().' - L'.$e->getLine().' <a class="pointer" onclick="$(this).next(\'div\').toggle()"><i class="fas fa-search-plus"></i> StackTrace</a><div class="hide">'.$e->getTraceAsString ().'<code>'.$lastQuery.'</code></div>');
  576. }catch(Exception $e){
  577. error($e->getMessage().' - L'.$e->getLine().' <a class="pointer" onclick="$(this).next(\'div\').toggle()"><i class="fas fa-search-plus"></i> StackTrace</a><div class="hide">'.$e->getTraceAsString ().'</div>');
  578. }
  579. ob_end_flush();
  580. //Crée une colonne temporaire pour stocker des ids (INT only)
  581. function temp_db_column($class, $colName){
  582. if(!$class || !$colName) throw new Exception("Paramètre manquant (temp_db_column)");
  583. $result = $class::staticQuery('SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "'.BASE_NAME.'" AND TABLE_NAME = "'.$class::tableName().'" AND COLUMN_NAME = ? ', array($colName))->fetch();
  584. if(!$result[0]) $class::staticQuery('ALTER TABLE '.$class::tableName().' ADD ? INT NULL', array($colName));
  585. }
  586. function execution_time($time_start){
  587. $time_end = microtime(true);
  588. $time = $time_end - $time_start;
  589. return info("Temps d'execution : ".round($time,4)." secondes");
  590. }
  591. //is not null or empty
  592. function inoe($column,$row){
  593. return (isset($row[$column]) && !empty(cleanChar($row[$column])));
  594. }
  595. //filter array with regex on key
  596. function preg_array_key_exists($pattern, $array) {
  597. $keys = array_keys($array);
  598. return (int) preg_grep($pattern,$keys);
  599. }
  600. function title($text){
  601. output('<hr/><h4>'.$text.'</h4>');
  602. }
  603. //Déplace une table
  604. function move_table($from,$to){
  605. User::staticQuery('DROP TABLE IF EXISTS '.$to.';');
  606. User::staticQuery('ALTER TABLE '.$from.' RENAME TO '.$to.';');
  607. }
  608. //Copie une table
  609. function copy_table($from,$to){
  610. User::staticQuery('DROP TABLE IF EXISTS '.$to.';');
  611. User::staticQuery('CREATE TABLE '.$to.' LIKE '.$from.'; INSERT '.$to.' SELECT * FROM '.$from.';');
  612. }
  613. //autoriser l'accès a la table pour un user spécifique
  614. function grant_table($base,$table,$user){
  615. User::staticQuery("GRANT SELECT,INSERT,UPDATE,REFERENCES ON `".$base."`.`".$table."` TO '".$user."'@'localhost';");
  616. }
  617. function info($text){
  618. output(date('H:i:s').' | '.$text.'</br>');
  619. }
  620. function error($text,$type="danger"){
  621. output('<div class="alert alert-'.$type.'"><button type="button" class="close" data-dismiss="alert" aria-label="Close">
  622. <span aria-hidden="true">&times;</span>
  623. </button>
  624. <strong>Erreur: </strong> '.date('H:i:s').' | '.$text.'
  625. </div>');
  626. }
  627. function cleanChar($text){
  628. $text = utf8_encode($text);
  629. if(strlen($text)==1 && ord($text)==0) $text = '';
  630. return $text;
  631. }
  632. function output($text){
  633. echo $text;
  634. flush();
  635. ob_flush();
  636. }
  637. function addStep($label,$callback){
  638. global $steps;
  639. if(!isset($steps)) $steps = array();
  640. $slug = preg_replace('|[^a-z0-9]|i', '-', $label);
  641. $slug = mb_strtolower(preg_replace('|-{2,}|i', '-', $slug));
  642. $steps[$slug] = array('label'=>$label,'callback'=>$callback);
  643. }
  644. function dbextract($sql){
  645. global $db,$lastQuery;
  646. $lastQuery = $sql;
  647. $query = $db->prepare($sql);
  648. $query->execute();
  649. $results = $query->fetchAll(PDO::FETCH_ASSOC);
  650. return $results;
  651. }
  652. function mysqldump($base,$user,$password){
  653. $command = '';
  654. if(PHP_OS =='WINNT'){
  655. if(MYSQL_DUMP_FILE==''){
  656. error("Le dump de la base est impossible sous windows, a moins de remplir la constante 'MYSQL_DUMP_FILE' avec le chemin vers l'executable mysqldump.exe, la migration se poursuit quand même...","warning");
  657. }else{
  658. $command .= '"'.MYSQL_DUMP_FILE.'" ';
  659. }
  660. }else{
  661. $command .= 'mysqldump ';
  662. }
  663. $dumpfile = DUMP_DIRECTORY.date('Y-m-d_h-i').".sql";
  664. $command .= "--routines -h ".BASE_HOST." --user=$user --password=$password $base > ".$dumpfile;
  665. echo $command;
  666. exec($command);
  667. if(!file_exists($dumpfile)) throw new Exception("Impossible de créer le backup");
  668. if(filesize($dumpfile)==0) throw new Exception("Le fichier de dump est vide");
  669. }
  670. function mysqlrestore($base,$user,$password,$dumpfile){
  671. $command = '';
  672. if(PHP_OS =='WINNT'){
  673. if(MYSQL_DUMP_FILE==''){
  674. error("Le dump de la base est impossible sous windows, a moins de remplir la constante 'MYSQL_DUMP_FILE' avec le chemin vers l'executable mysqldump.exe, la migration se poursuit quand même...","warning");
  675. }else{
  676. $command .= '"'.str_replace('dump.exe','.exe',MYSQL_DUMP_FILE).'" ';
  677. }
  678. }else{
  679. $command .= 'mysql ';
  680. }
  681. $command .= " -h ".BASE_HOST." -u {$user} -p{$password} {$base} < $dumpfile";
  682. exec($command);
  683. }
  684. ?>
  685. </div>
  686. <?php if($conf->get('offline_mode')): ?>
  687. <script src="../js/vendor/jquery.min.js"></script>
  688. <?php else: ?>
  689. <script
  690. src="https://code.jquery.com/jquery-3.2.1.min.js"
  691. integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  692. crossorigin="anonymous"></script>
  693. <script>window.jQuery || document.write('<script src="js/vendor/jquery.min.js"><\/script>')</script>
  694. <?php endif ?>
  695. <script src="../js/vendor/popper.min.js"></script>
  696. <script src="../js/bootstrap.min.js"></script>
  697. <script src="../js/vendor/jquery-ui.min.js"></script>
  698. <script src="../js/vendor/bootstrap3-typeahead.min.js"></script>
  699. <script src="../js/plugins.js"></script>
  700. <script src="../js/main.js"></script>
  701. <script src="../js/component.js"></script>
  702. </body>
  703. </html>