Commit 167bd1f87d7e69aca69a5916465b95775b48d5b3

Authored by Elena Budnik
2 parents d173bd15 04eef959

Merge branch 'ws_transfert' into 'master'

Ws transfert

See merge request !23
desktop.php
... ... @@ -33,8 +33,8 @@
33 33  
34 34 <!-- <script type="text/javascript" src="js/lib/ext/builds/ext-core.js"></script> -->
35 35 <!-- <script type="text/javascript" src="js/lib/ext/bootstrap.js"></script> -->
36   -<!-- <script type="text/javascript" src="js/lib/ext/ext-all-debug-w-comments.js"></script>-->
37   - <script type="text/javascript" src="js/lib/ext/ext-all.js"></script>
  36 +<!-- <script type="text/javascript" src="js/lib/ext/ext-all-debug-w-comments.js"></script> -->
  37 + <script type="text/javascript" src="js/lib/ext/ext-all.js"></script>
38 38 <!-- <script type="text/javascript" src="js/lib/ext/ext-all-dev.js"> -->
39 39 <!-- <script type="text/javascript" src="js/lib/ext-override.js"></script> -->
40 40  
... ... @@ -76,8 +76,10 @@
76 76  
77 77 var myDesktopApp;
78 78  
  79 + var isMigration = true;
79 80 var sessionID = '<?php echo $sessionID; ?>';
80 81 var isFirstVisit = '<?php echo $usrMgr->isFirst; ?>';
  82 + var isOldWS = '<?php echo $usrMgr->isOldWS; ?>';
81 83 var isSpecialInfo = '<?php echo $usrMgr->isSpecialInfo; ?>';
82 84 var isNewInfo = '<?php echo $usrMgr->isNewInfo; ?>';
83 85 var news = '../data/' + sessionID + '/INFO';
... ... @@ -91,11 +93,11 @@
91 93  
92 94 var helpDir = 'help/';
93 95 var isGuest = sessionID.match('guest');
94   -
  96 +
95 97 var max_uploaded_file_size = '<?php echo MAX_UPLOADED_FILESIZE; ?>';
96 98 var guestSessionDuration = '<?php echo GuestSessionDuration*60; ?>'; // in secs
97 99 var maxGuestTimeInterval = '<?php echo MaxGuestTimeInterval; ?>'; // in days
98   -
  100 +
99 101 //create mask class (LoadMask for elements has been deprecated, use Ext.dom.Element.mask & Ext.dom.Element.unmask)
100 102 var AMDAMask = new Ext.Class({
101 103 show : function(interactivePlot)
... ... @@ -116,7 +118,7 @@
116 118 maskMsg.style.zIndex = '99999';
117 119 if (interactivePlot)
118 120 {
119   - var killBtn = Ext.get('killopBtn');
  121 + var killBtn = Ext.get('killopBtn');
120 122 killBtn.on('click',function(e,t) {
121 123 AmdaAction.killPlotRequest(function (result, e)
122 124 {
... ...
js/app/AmdaApp.js
... ... @@ -180,7 +180,6 @@ Ext.define(&#39;amdaApp.AmdaApp&#39;, {
180 180 },
181 181 ready : function ()
182 182 {
183   - //AKKA - Clean user WS
184 183 AmdaAction.cleanUserWS(function(res,e){},this);
185 184 }
186 185 },
... ... @@ -236,7 +235,19 @@ Ext.define(&#39;amdaApp.AmdaApp&#39;, {
236 235 buttons: Ext.Msg.OK
237 236 });
238 237 },
239   -
  238 + //create InfoBox
  239 + infoMsgLong : function(msg) {
  240 + Ext.Msg.show({
  241 + title: 'AMDA Info',
  242 + cls: 'infoMsgLong',
  243 + msg: msg,
  244 + modal: false,
  245 + autoScroll: true,
  246 + resizable: true,
  247 + icon: Ext.Msg.INFO,
  248 + buttons: Ext.Msg.OK
  249 + });
  250 + },
240 251 //create WarningBox
241 252 warningMsg : function(msg) {
242 253 Ext.Msg.show({
... ... @@ -587,12 +598,45 @@ Ext.define(&#39;amdaApp.AmdaApp&#39;, {
587 598 'MB rests');
588 599 }
589 600  
590   - if (isFirstVisit && !isGuest) {
591   - if (isSpecialInfo) {
592   - myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function(module) {
593   - module.createWindow(isSpecialInfo, 'Welcome to AMDA', true);
594   - });
595   - } else {
  601 + if (isFirstVisit && !isGuest) {
  602 +
  603 + if (isMigration) { // isSpecialInfo
  604 + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function(module) {
  605 + module.createWindow(isSpecialInfo, 'Welcome on AMDA', true);
  606 + if ( isOldWS ) {
  607 + var win = myDesktopApp.getDesktop().getWindow(myDesktopApp.dynamicModules.info.id);
  608 + win.on({
  609 + show : function() {
  610 + Ext.Msg.show({
  611 + title:'Welcome on new AMDA',
  612 + msg: 'It is your first visit on the new version of AMDA.<br/>'+
  613 + 'Do you want to copy here your workspace from the old AMDA ?',
  614 + buttons: Ext.Msg.YESNO,
  615 + icon: Ext.Msg.QUESTION,
  616 + fn : function (btn) {
  617 + if (btn == 'yes') {
  618 + loadMask.show();
  619 + AmdaAction.convertWS(function(res,e){
  620 + var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
  621 + explorerModule.filtersStore.reload();
  622 + loadMask.hide();
  623 +
  624 + if (res.success == true) {
  625 + myDesktopApp.infoMsgLong('<b>Your Wokspace has been copied to new AMDA</b><br/><br/> ' + res.msg);
  626 + }
  627 + else {
  628 + myDesktopApp.errorMsg(res.error);
  629 + }
  630 + });
  631 + }
  632 + }
  633 + });
  634 + },
  635 + scope : this });
  636 + }
  637 + })
  638 + }
  639 + else {
596 640 myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.help.id, true, function(module) {
597 641 module.createWindow();
598 642 });
... ... @@ -601,7 +645,7 @@ Ext.define(&#39;amdaApp.AmdaApp&#39;, {
601 645 else {
602 646 if (isSpecialInfo && !isNewInfo) {
603 647 myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function(module) {
604   - module.createWindow(isSpecialInfo, 'Welcome to AMDA', true);
  648 + module.createWindow(isSpecialInfo, 'Welcome on AMDA', true);
605 649 });
606 650 }
607 651 }
... ...
js/app/controllers/AboutModule.js
... ... @@ -7,92 +7,89 @@
7 7 * This Module describe new functionalities of AMDA-NG4
8 8 * @author CDA
9 9 * @version $Id: AboutModule.js 2397 2014-06-03 10:21:28Z elena $
10   - * TODO Do we need real Module ???
11 10 */
12 11  
13   -Ext.define('amdaDesktop.AboutModule', {
14   -
15   - extend: 'amdaDesktop.AmdaModule',
  12 +Ext.define('amdaDesktop.AboutModule',
  13 +{
  14 + extend: 'amdaDesktop.AmdaModule',
  15 + contentId : 'infoUI',
  16 + file : 'releaseNotes.' + AMDAVERSION,
16 17  
17   - contentId : 'infoUI',
18   - file : 'releaseNotes.' + AMDAVERSION,
19   -
20   - createWindow : function(file, title, specialInfo)
21   - {
22   - var desktop = myDesktopApp.getDesktop();
23   - var win = desktop.getWindow(this.id);
24   - var theTitle = title ? title : this.title;
25   -
26   - if (!AMDAVERSION) this.file = 'about';
27   -
28   - var theFile = file ? file : this.file;
29   - if (!win) {
30   - win = desktop.createWindow({
31   - id: this.id,
32   - title: theTitle,
33   - file : theFile,
34   - width: 650,
35   - height: 570,
36   - autoScroll : true,
37   - minimizable: false,
38   - maximizable: false,
39   - bodyStyle: 'background:#ffffee; padding:15px 15px 15px 15px;',
40   - bodyCls : 'infoWindow',
41   - loader : {
42   - url : helpDir + theFile,
43   - loadMask : false,
44   - autoLoad : true // important
45   - },
46   - iconCls: this.icon,
47   - animCollapse:false,
48   - constrainHeader:true
49   - });
  18 + createWindow : function(file, title, specialInfo)
  19 + {
  20 + var desktop = myDesktopApp.getDesktop();
  21 + var win = desktop.getWindow(this.id);
  22 + var theTitle = title ? title : this.title;
  23 +
  24 + if (!AMDAVERSION) this.file = 'about';
  25 +
  26 + var theFile = file ? file : this.file;
  27 + if (!win) {
  28 + win = desktop.createWindow({
  29 + id: this.id,
  30 + title: theTitle,
  31 + file : theFile,
  32 + width: 650,
  33 + height: 570,
  34 + autoScroll : true,
  35 + minimizable: false,
  36 + maximizable: false,
  37 + bodyStyle: 'background:#ffffee; padding:15px 15px 15px 15px;',
  38 + bodyCls : 'infoWindow',
  39 + loader : {
  40 + url : helpDir + theFile,
  41 + loadMask : false,
  42 + autoLoad : true // important
  43 + },
  44 + iconCls: this.icon,
  45 + animCollapse:false,
  46 + constrainHeader:true
  47 + });
50 48  
51   - if (specialInfo) {
52   - win.add({ xtype: 'toolbar',
53   - items: [ {
54   - text: 'AMDA\'s ABCs',
55   - scope : this,
56   - handler: function() {
57   - myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.help.id, true, function (module) {
58   - module.createWindow();
59   - });
60   - }
61   - },'-',
62   - '->', '-',
63   - {
64   - text: 'Stop showing this window on next login',
65   - scope : this,
66   - handler: function() {
67   - AmdaAction.deleteSpecialInfo(win.file);
68   - Ext.MessageBox.show({title:'Warning',
69   - msg: 'OK. Close the window right now?',
70   - width: 300,
71   - buttons: Ext.MessageBox.OKCANCEL,
72   - fn : function(btn) {
73   - if (btn == 'cancel') return;
74   - win.close();
75   - },
76   - icon: Ext.MessageBox.WARNING,
77   - scope : this
78   - });
79   - }
80   - }
81   - ]});
82   - }
83   -
84   - win.show();
85   - }
86   - else if (win.file === theFile) {
87   - win.toFront();
88   - }
89   - else {
90   - win.loader.url = helpDir + theFile;
91   - win.loader.load();
92   - win.setTitle(theTitle);
93   - win.file = theFile;
94   - win.toFront();
95   - }
96   - }
97   -
  49 + if (specialInfo) {
  50 + win.add({ xtype: 'toolbar',
  51 + items: [ {
  52 + text: 'AMDA\'s ABCs',
  53 + scope : this,
  54 + handler: function() {
  55 + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.help.id, true, function (module) {
  56 + module.createWindow();
  57 + });
  58 + }
  59 + },'-',
  60 + '->', '-',
  61 + {
  62 + text: 'Stop showing this window on next login',
  63 + scope : this,
  64 + handler: function() {
  65 + AmdaAction.deleteSpecialInfo(win.file);
  66 + Ext.MessageBox.show({title:'Warning',
  67 + msg: 'OK. Close the window right now?',
  68 + width: 300,
  69 + buttons: Ext.MessageBox.OKCANCEL,
  70 + fn : function(btn) {
  71 + if (btn == 'cancel') return;
  72 + win.close();
  73 + },
  74 + icon: Ext.MessageBox.WARNING,
  75 + scope : this
  76 + });
  77 + }
  78 + }
  79 + ]});
  80 + }
  81 +
  82 + win.show();
  83 + }
  84 + else if (win.file === theFile) {
  85 + win.toFront();
  86 + }
  87 + else {
  88 + win.loader.url = helpDir + theFile;
  89 + win.loader.load();
  90 + win.setTitle(theTitle);
  91 + win.file = theFile;
  92 + win.toFront();
  93 + }
  94 + }
98 95 });
... ...
js/resources/css/amda.css
... ... @@ -239,6 +239,10 @@ background-image: url(../images/16x16/error.png) !important;
239 239 background-color: yellow !important;
240 240 }
241 241  
  242 +.infoMsgLong .x-window-body > .x-box-inner {
  243 + overflow: scroll;
  244 + }
  245 +
242 246 /* datasets information windows */
243 247  
244 248 .infoWindow table.contact {
... ...
php/classes/UserMgr.php
... ... @@ -25,6 +25,7 @@ class UserMgr
25 25 protected $amdaClient; //client to dd webservice
26 26  
27 27 public $isFirst = false;
  28 + public $isOldWS = true;
28 29 public $isNewInfo = false;
29 30 public $isSpecialInfo = null;
30 31  
... ... @@ -488,32 +489,36 @@ unlink(USERWSDIR.&#39;RemoteParams.xml&#39;);
488 489 /*****************************************************************
489 490 * PUBLIC FUNCTIONS
490 491 *****************************************************************/
491   -// // migration from old to new AMDA
492   -// public function convertWS() {
493   -//
494   -// $convert = new UserWsTransfer($this->user);
495   -//
496   -// $res = $convert->checkWS();
497   -// if (!$res['success']) return $res;
498   -//
499   -// $res = $convert->transferDerived();
500   -// $msg = $res['msg'];
501   -//
502   -// $res = $convert->transferTimeTables();
503   -// $msg .= $res['msg'];
504   -//
505   -// $res = $convert->transferConditions();
506   -// $msg .= $res['msg'];
507   -//
  492 + // migration from old to new AMDA
  493 + public function convertWS()
  494 + {
  495 + $convert = new UserWsTransfer($this->user);
  496 +
  497 + $res = $convert->checkWS();
  498 + if (!$res['success']) return $res;
  499 +
  500 + $res = $convert->transferMyData();
  501 + $msg = $res['msg'];
  502 +
  503 + $res = $convert->transferDerived();
  504 + $msg .= $res['msg'];
  505 +
  506 + $res = $convert->transferTimeTables();
  507 + $msg .= $res['msg'];
  508 +
  509 + $res = $convert->transferConditions();
  510 + $msg .= $res['msg'];
  511 +
508 512 // $res = $convert->transferRequests();
509 513 // $msg .= $res['msg'];
510   -//
511   -// $res = $convert->transferMyData();
512   -// $msg .= $res['msg'];
513   -//
514   -// error_log('Transfer workspace from old AMDA for '.$this->user, 1, 'amda@irap.omp.eu');
515   -// return array('success' => true, 'msg' => $msg);
516   -// }
  514 +
  515 + $res = $convert->transferFilters();
  516 + $msg .= $res['msg'];
  517 +
  518 +
  519 + // error_log('Transfer workspace from old AMDA for '.$this->user, 1, 'amda@irap.omp.eu');
  520 + return array('success' => true, 'msg' => $msg);
  521 + }
517 522  
518 523 public function setPath()
519 524 {
... ... @@ -522,9 +527,9 @@ unlink(USERWSDIR.&#39;RemoteParams.xml&#39;);
522 527 $this->userdir = USERPATH."/".$this->user."/";
523 528 }
524 529 // for testing purposes
525   - else if (defined('TRANSFERUSER')) {
526   - $this->userdir = BASE_PATH."test/".TRANSFERUSER."/";
527   - }
  530 +// else if (defined('TRANSFERUSER')) {
  531 +// $this->userdir = BASE_PATH."test/".TRANSFERUSER."/";
  532 +// }
528 533 else if (isset($this->user)) {
529 534 $this->userdir = USERPATH."/".$this->user."/";
530 535 }
... ... @@ -569,7 +574,12 @@ unlink(USERWSDIR.&#39;RemoteParams.xml&#39;);
569 574 if (!$this->createDir()) {
570 575 die("Login for ".$this->user." failed: Can't create WS dirs");
571 576 }
572   - $this->isFirst = true;
  577 + $this->isFirst = true;
  578 + $convert = new UserWsTransfer($this->user);
  579 +
  580 + $res = $convert->checkWS();
  581 + if (!$res['success'])
  582 + $this->isOldWS = false;
573 583 }
574 584  
575 585 if (file_exists($this->userdir.'newLogin')) {
... ... @@ -657,6 +667,7 @@ unlink(USERWSDIR.&#39;RemoteParams.xml&#39;);
657 667 {
658 668 if (file_exists(USERWSDIR.'LocalParams.xml'))
659 669 unlink(USERWSDIR.'LocalParams.xml');
  670 +
660 671 if (!copy(LocalData.'/LocalParams.xml', USERWSDIR.'LocalParams.xml'))
661 672 die("Login for ".$this->user." failed: Can't copy LocalParams.xml");
662 673  
... ...
php/classes/UserWsTransfer.php
1 1 <?php
2 2 /**
3 3 * @class UserWsTransfer
4   - * @version $Id: UserWsTransfer.php 1718 2013-08-28 15:52:38Z myriam $
5   - *
6 4 */
7 5  
8   - class UserWsTransfer {
  6 +class UserWsTransfer {
9 7  
10   - private $ws, $Mgr;
11   - private $wsDir;
12   - private $ws_deleted;
  8 + private $oldWs, $newWs, $Mgr;
  9 + private $oldWsDir, $newWsDir;
  10 + private $ws_deleted, $wsd_deleted, $pairs;
13 11  
14   - function __construct($user) {
15   -
16   - define('OLDUSERPATH', ROOT_PATH.'USERS/');
17   - define('TRANSFERUSER', $user);
18   - define('CONVERSIONDIR', BASE_PATH.'utils/conversion/');
19   -
20   - $this->ws = new DomDocument("1.0");
21   - $this->wsDir = OLDUSERPATH.TRANSFERUSER.'/WS/';
22   -
23   - $this->ws_deleted = array();
24   - }
25   -
26   - public function checkWS() {
27   -
28   - // old ws
29   - if (!is_dir(OLDUSERPATH.TRANSFERUSER)) {
30   - error_log('no '.TRANSFERUSER.' at old AMDA',1,email);
31   - return array('success' => false, 'error' => 'Sorry, it seems you have no account at old AMDA');
32   - }
33   -
34   - if (!file_exists($this->wsDir.'ws.xml')) {
35   - error_log('no ws.xml for '.TRANSFERUSER,1,email);
36   - return array('success' => false, 'error' => 'Sorry, we failed to find your workspace at old AMDA');
37   - }
38   -
39   - if (!$this->ws->load($this->wsDir.'ws.xml')) {
40   - error_log('cannot load ws.xml for '.TRANSFERUSER,1,email);
41   - return array('success' => false, 'error' => 'Sorry, we failed to access your workspace at old AMDA');
42   - }
43   -
44   - return array('success' => true);
45   -
46   - }
47   -
48   - public function hasAlias($expression) {
  12 + function __construct($user)
  13 + {
  14 + define('OLDUSERPATH', 'http://cdpp1.irap.omp.eu/AMDA-NG/data/');
  15 + // define('OLDUSERPATH', 'http://amda-dev.irap.omp.eu/~budnik/AMDA-NG4/trunk/data/');
  16 + define('NEWUSERPATH', '/home/budnik/AMDA/AMDA_IHM/data/');
  17 + define('TRANSFERUSER', $user);
  18 + define('CONVERSIONDIR', '/home/budnik/AMDA/AMDA_Migration/conversion/');
  19 +
  20 + $this->oldWs = new DomDocument("1.0");
  21 + $this->newWs = new DomDocument("1.0");
  22 +
  23 + $this->oldWsDir = OLDUSERPATH.TRANSFERUSER.'/WS/';
  24 + $this->newWsDir = NEWUSERPATH.TRANSFERUSER.'/WS/';
  25 +
  26 + if (!is_dir(NEWUSERPATH.TRANSFERUSER.'/WS'))
  27 + mkdir(NEWUSERPATH.TRANSFERUSER.'/WS', 0775);
  28 +
  29 + $this->ws_deleted = array();
  30 + $this->wsd_deleted = array();
  31 + $this->getModified();
  32 + }
  33 +
  34 + private function getObsolete() {
  35 +
  36 + $deletedXML = new DomDocument("1.0");
  37 + $deletedXML->load(CONVERSIONDIR."Deleted.xml");
  38 + $deletedNodes = $deletedXML->getElementsByTagName('deleted');
  39 +
  40 + $deleted = array();
  41 + foreach ($deletedNodes as $node)
  42 + $deleted[] = $node->getAttribute('xml:id');
  43 +
  44 + return $deleted;
  45 + }
  46 +
  47 + private function getNotreadyFunctions() {
  48 +
  49 + $deletedXML = new DomDocument("1.0");
  50 + $deletedXML->load(CONVERSIONDIR."Functions.xml");
  51 + $deletedNodes = $deletedXML->getElementsByTagName('deleted');
  52 +
  53 + $notready = array();
  54 + foreach ($deletedNodes as $node)
  55 + $notready[] = $node->getAttribute('xml:id');
  56 +
  57 + return $notready;
  58 + }
  59 +
  60 + private function getNotready() {
  61 +
  62 + $deletedXML = new DomDocument("1.0");
  63 + $deletedXML->load(CONVERSIONDIR."NotReady.xml");
  64 + $deletedNodes = $deletedXML->getElementsByTagName('deleted');
  65 +
  66 + $notready = array();
  67 + foreach ($deletedNodes as $node)
  68 + $notready[] = $node->getAttribute('xml:id');
  69 +
  70 + return $notready;
  71 + }
  72 +
  73 + private function deleteParam($exp, $deleted)
  74 + {
  75 + $toDelete = false;
  76 +
  77 + foreach ($deleted as $item) {
  78 + if (strpos($exp, $item) !== false) {
  79 + $toDelete = true;
  80 + break;
  81 + }
  82 + }
  83 +
  84 + return $toDelete;
  85 + }
  86 +
  87 + private function getWs($exp)
  88 + {
  89 + $ws = array();
  90 +
  91 + if (strpos($exp, 'ws_') !== false) {
  92 + $arr = $this->delimitIt($exp);
  93 + foreach ($arr as $item) {
  94 + if (strpos($item, 'ws_') !== false)
  95 + $ws[] = substr($item,3);
  96 + }
  97 + return $ws;
  98 + }
  99 + return false;
  100 + }
  101 +
  102 + private function delimitIt($chain) {
49 103  
50   - return (strpos($expression, "#") !== false);
51   -
52   - }
53   -
54   -
55   - public function replaceAliases($expression){
56   -
57   - $aliasXML = new DomDocument("1.0");
58   - $aliasXML->load($this->wsDir.'alias.xml');
59   - $aliases_ = $aliasXML->getElementsByTagName('alias');
60   -
61   - if ($aliases_->length == 0) return $expression;
62   -
63   - $aliases = array();
64   - foreach ($aliases_ as $alias) {
65   - $aliases["#".$alias->getAttribute("name")] = $alias->nodeValue;
66   - }
67   -// sort in desc order by key (alias itself)
68   - krsort($aliases, SORT_NATURAL);
69   -
70   - foreach ($aliases as $alias => $param) {
71   -
72   - if (!$this->hasAlias($expression))
73   - break;
74   - if (strpos($expression, $alias) !== false) {
75   - $newExp = str_replace($alias, $param, $expression);
76   - $expression = $newExp;
77   - }
78   - }
79   - return $expression;
80   - }
81   -
82   -//duplication of FilesMgr method
83   - public function getSampling($fileName, $format) {
84   -
85   - if ($format === 'cdf') {
86   - copy($fileName, "temp.cdf");
87   - exec('cdfsamplingfromdata ', $result);
88   - unlink("temp.cdf");
89   - $minSamp = $result[count($result)-1];
90   - }
91   - else if ($format === 'cef') {
92   - exec('cefsampling '.$fileName, $result);
93   - $minSamp = $result[count($result)-1];
94   - }
95   - else $minSamp = null;
96   -//TODO if min & max
97   - return $minSamp;
98   -
99   - }
100   -
101   -
102   - public function deleteParam($exp, $isPlot) {
103   -
104   - $deletedXML = new DomDocument("1.0");
105   -
106   - if ($isPlot) $deletedXML->load(CONVERSIONDIR.'Plot_Deleted.xml');
107   - else $deletedXML->load(CONVERSIONDIR.'Deleted.xml');
  104 + $delimiter = '[]+,/*()^<>&|=[-]+';
  105 + $array = split($delimiter,$chain);
  106 + if (trim(end($array)) == "") array_pop($array);
108 107  
109   - $deletedNodes = $deletedXML->getElementsByTagName('deleted');
110   - $toDelete = false;
111   -
112   - if (strpos($exp, "CDAWEB") !== false)
113   - return true;
114   -
115   -
116   - foreach ($deletedNodes as $item) {
117   - if (strpos($exp, $item->getAttribute('xml:id')) !== false) {
118   - $toDelete = true;
119   - break;
120   - }
121   - }
122   -
123   - return $toDelete;
124   -}
125   -
126   - public function updateParams($expression, $isPlot){
  108 + return $array;
  109 + }
127 110  
  111 + private function getModified()
  112 + {
  113 + $convertXML = new DomDocument("1.0");
  114 + $modifiedFile = CONVERSIONDIR.'Modified.xml';
  115 +
  116 + if (!$convertXML->load($modifiedFile))
  117 + error_log('ERROR loading '.$modifiedFile,1,email);
  118 + $convertedNodes = $convertXML->getElementsByTagName('param_convert');
  119 +
  120 + foreach ($convertedNodes as $item) {
  121 + $pairs[$item->getAttribute('oldid')] = $item->getAttribute('xml:id');
  122 + }
  123 + krsort($pairs, SORT_NATURAL);
  124 +
  125 + $this->pairs = $pairs;
  126 + }
  127 +
  128 + private function updateParams($expression)
  129 + {
  130 + $newExp = strtr($expression, $this->pairs);
  131 + $expression = $newExp;
  132 +
  133 + return $expression;
  134 + }
  135 +
  136 + //duplication of FilesMgr method
  137 + public function getSampling($fileName, $format) {
  138 +
  139 + if ($format === 'cdf') {
  140 + copy($fileName, "temp.cdf");
  141 + exec('cdfsamplingfromdata ', $result);
  142 + unlink("temp.cdf");
  143 + $minSamp = $result[count($result)-1];
  144 + }
  145 + else if ($format === 'cef') {
  146 + exec('cefsampling '.$fileName, $result);
  147 + $minSamp = $result[count($result)-1];
  148 + }
  149 + else $minSamp = null;
  150 + //TODO if min & max
  151 + return $minSamp;
  152 + }
  153 +
  154 + protected function createDom()
  155 + {
  156 + $types = array('param' => 'derived', 'mydata' => 'myData');
  157 +
  158 + $rootElement = $this->newWs->createElement('ws');
  159 + foreach ($types as $key => $value)
  160 + {
  161 + $contentId = $value.'Param-treeRootNode';
  162 + $contentTag = $key.'List';
  163 + $typeElement = $this->newWs->createElement($contentTag);
  164 + $typeElement->setAttribute('xml:id', $contentId);
  165 + $rootElement->appendChild($typeElement);
  166 + }
  167 +
  168 + $this->newWs->appendChild($rootElement);
  169 + // $this->newWs->save($this->newWsDir.'WsParams.xml');
  170 + }
  171 +
  172 + public function checkWS()
  173 + {
  174 + // old ws
  175 + if (!curl_init(OLDUSERPATH.TRANSFERUSER)) {
  176 + error_log('no '.TRANSFERUSER.' at old AMDA',1,email);
  177 + return array('success' => false, 'error' => 'Sorry, it seems you have no account at old AMDA');
  178 + }
  179 +
  180 + if (!curl_init($this->oldWsDir)) {
  181 + error_log('no ws.xml for '.TRANSFERUSER,1,email);
  182 + return array('success' => false, 'error' => 'Sorry, we failed to find your workspace at old AMDA');
  183 + }
  184 +
  185 + return array('success' => true);
  186 + }
  187 +
  188 + public function transferDerived()
  189 + {
  190 + $msg = '<br/><b><i>Derived Params:</i></b><br/><br/>';
  191 + $msg .= '<i>Note</i> : Parameters made from Remote Base parameters are not copied <br/><br/>';
  192 + if (!$this->oldWs->load($this->oldWsDir.'WsParams.xml')) {
  193 + error_log('cannot load WsParams.xml for '.TRANSFERUSER,1,email);
  194 + return array('success' => false, 'error' => 'Sorry, we failed to get your Derived Params from old AMDA');
  195 + }
  196 +
  197 + if (!file_exists($this->newWsDir.'WsParams.xml'))
  198 + $this->createDom();
  199 + else
  200 + $this->newWs->load($this->newWsDir.'WsParams.xml');
  201 +
  202 + $deleted = $this->getObsolete();
  203 + $notready = $this->getNotready();
  204 + $notreadyFunctions = $this->getNotreadyFunctions();
  205 +
  206 + $wsParamNode = $this->newWs->getElementsByTagName('paramList')->item(0);
  207 +
  208 + $wsParamsOld = $this->oldWs->getElementsByTagName('param');
  209 +
  210 + if ($wsParamsOld->length == 0) {
  211 + return array('success' => true, 'msg' => 'No parameters');
  212 + }
  213 +
  214 + $paramXml = new DomDocument("1.0");
  215 + $msg .= 'Not copied derived parameters :<br/>';
  216 +
  217 + foreach ($wsParamsOld as $param) {
  218 + $id = $param->getAttribute('xml:id');
  219 + $name = $param->getAttribute('name');
  220 +
  221 + $expression = $param->getAttribute('buildchain');
  222 +
  223 + if ($this->deleteParam($expression,$deleted)) {
  224 + $msg .= '<li><i>'.$name.'</i> : uses obsolete param<br/> '.$expression.'<br/>';
  225 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  226 + $this->ws_deleted[] = $name;
  227 + continue;
  228 + }
  229 +
  230 + if ($this->deleteParam($expression,$notready)) {
  231 + $msg .= '<li><i>'.$name.'</i> : uses param not ready yet <br/> '.$expression.'<br/>';
  232 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  233 + $this->ws_deleted[] = $name;
  234 + continue;
  235 + }
  236 +
  237 + if ($this->deleteParam($expression,$notreadyFunctions)) {
  238 + $msg .= '<li><i>'.$name.'</i> : uses function not ready yet <br/> '.$expression.'<br/>';
  239 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  240 + $this->ws_deleted[] = $name;
  241 + continue;
  242 + }
  243 +
  244 + if (!empty($this->wsd_deleted))
  245 + if ($this->deleteParam($expression,$this->wsd_deleted)) {
  246 + $msg .= '<li><i>'.$name.'</i> : uses obsolete myData param<br/> '.$expression.'<br/>';
  247 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  248 + $this->ws_deleted[] = $name;
  249 + continue;
  250 + }
  251 +
  252 + if ($this->deleteParam($expression,array("CDAWEB","MAPSKP","VEXGRAZ","IMPEX"))) {
  253 + $msg .= '<li><i>'.$name.'</i> : uses remote params <br/> '.$expression.'<br/>';
  254 + $this->ws_deleted[] = $name;
  255 + continue;
  256 + }
  257 +
  258 + $expressionUpdated = $this->updateParams($expression);
  259 + $wsParamNode->appendChild($this->newWs->importNode($param));
  260 +
  261 + $paramXml->load($this->oldWsDir.$id.'.xml');
  262 + $expressionNode = $paramXml->getElementsByTagName('buildchain')->item(0);
  263 + $expressionNode->nodeValue = $expressionUpdated;
  264 + $paramXml->save($this->newWsDir.$id.'.xml');
  265 + }
  266 +
  267 + // check of 'ws bricks' were deleted
  268 + $newParams = $this->newWs->getElementsByTagName('param');
  269 + $xp = new domxpath($this->newWs);
  270 + $paramsToRemove = array();
  271 +
  272 + foreach ($newParams as $param) {
  273 + $id = $param->getAttribute('xml:id');
  274 + $name = $param->getAttribute('name');
  275 +
  276 + $expression = $param->getAttribute('buildchain');
  277 + if ($wsParams = $this->getWs($expression)) {
  278 + foreach ($wsParams as $wsParam) {
  279 + $res = $xp->query("//param[@name='".trim($wsParam)."']");
  280 + if ($res->length == 0) {
  281 + unlink($this->newWsDir.$id.'.xml');
  282 + $paramsToRemove[] = $param;
  283 + $this->ws_deleted[] = $name;
  284 + $msg .= '<li><i>'.$name.'</i> : uses obsolete / not ready ws param : <br/> '.$expression.'<br/>';
  285 + }
  286 + }
  287 + }
  288 + }
  289 +
  290 + foreach ($paramsToRemove as $paramToRemove) {
  291 + $paramToRemove->parentNode->removeChild($paramToRemove);
  292 + }
  293 +
  294 + $this->newWs->save($this->newWsDir.'WsParams.xml');
  295 + $copied = $newParams->length - count($paramsToRemove);
  296 +
  297 + $msg .= '<br/><i>Copied : </i>'.$copied.' derived parameters<br/><br/>';
  298 + return array('success' => true, 'msg' => $msg);
  299 + }
  300 +
  301 + public function transferTimeTables()
  302 + {
  303 + $msg = '<b><i>Time Tables:</i></b><br/><br/>';
  304 +
  305 + // get old time tab list
  306 + $this->newWs->load($this->oldWsDir.'Tt.xml');
  307 + $timeTabs = $this->newWs->getElementsByTagName('timetab');
  308 + if ($timeTabs->length == 0) {
  309 + $msg .= 'No time tables';
  310 + return array('success' => true, 'msg' => $msg);
  311 + }
  312 +
  313 + $oldTtDir = OLDUSERPATH.TRANSFERUSER."/TT/";
  314 + $newTtDir = NEWUSERPATH.TRANSFERUSER."/TT/";
  315 + foreach ($timeTabs as $tab) {
  316 + $id = $tab->getAttribute('xml:id');
  317 + copy($oldTtDir.$id.'.xml', $newTtDir.$id.'.xml');
  318 + }
  319 +
  320 + $this->newWs->save($this->newWsDir.'Tt.xml');
  321 + $msg .= '<i>Copied : </i>'.$timeTabs->length.' time tables<br/><br/>';
  322 + return array('success' => true, 'msg' => $msg);
  323 + }
128 324  
129   - $convertXML = new DomDocument("1.0");
130   -
131   - if ($isPlot) $fileNames = glob(CONVERSIONDIR.'*_convertPlot.xml');
132   - else $fileNames = glob(CONVERSIONDIR.'*_convert.xml');
133   -
134   -
135   - foreach ($fileNames as $file) {
136   -
137   - if (!$convertXML->load($file))
138   - error_log('ERROR loading '.$file,1,email);
139   - $convertedNodes = $convertXML->getElementsByTagName('param_convert');
  325 + public function transferConditions()
  326 + {
  327 + $msg = '<b><i>Requests</i></b><br/><br/>';
  328 + $msg .= '<i>Note :</i> Plot requests are not copied : too much difference new-old AMDA<br/<br/><br/>';
  329 + $oldRequestXml = new DomDocument("1.0");
  330 + $newRequestXml = new DomDocument("1.0");
  331 +
  332 + if (!$oldRequestXml->load($this->oldWsDir.'Request.xml')){
  333 + $msg .= ' No Requests File<br/>';
  334 + return array('success' => true, 'msg' => $msg);
  335 + }
  336 +
  337 + $condNodes = $oldRequestXml->getElementsByTagName('condition');
  338 + if ($condNodes->length == 0) {
  339 + $msg .= ' no DataMining requests to copy<br/>';
  340 + return array('success' => true, 'msg' => $msg);
  341 + }
  342 + $newRequestXml->load($this->newWsDir.'Request.xml');
  343 + $conditionRoot = $newRequestXml->getElementsByTagName('conditionList')->item(0);
  344 +
  345 + $condDir = OLDUSERPATH.TRANSFERUSER."/REQ/";
  346 +
  347 + $deleted = $this->getObsolete();
  348 + $notready = $this->getNotready();
  349 + $msg .= 'Not copied DataMining requests :<br/>';
  350 +
  351 + foreach ($condNodes as $condNode) {
  352 + $id = $condNode->getAttribute('xml:id');
  353 + $name = $condNode->getAttribute('name');
  354 + $cond = file($condDir.$id, FILE_IGNORE_NEW_LINES);
  355 +
  356 + $condObj = json_decode($cond[0]);
  357 + $expression = $condObj->expression;
  358 + if ($this->deleteParam($expression, $deleted)) {
  359 + $msg .= '<li><i>'.$name.'</i> : uses obsolete param<br/> '.$expression.'<br/>';
  360 + $cond_deleted[] = $name;
  361 + continue;
  362 + }
  363 +
  364 + if ($this->deleteParam($expression,$notready)) {
  365 + $msg .= '<li><i>'.$name.'</i> : uses param not ready yet<br/> '.$expression.'<br/>';
  366 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  367 + $cond_deleted[] = $name;
  368 + continue;
  369 + }
  370 +
  371 + if (!empty($this->wsd_deleted))
  372 + if ($this->deleteParam($expression,$this->wsd_deleted)) {
  373 + $msg .= '<li><i>'.$name.'</i> : uses obsolete myData param<br/> '.$expression.'<br/>';
  374 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  375 + $cond_deleted[] = $name;
  376 + continue;
  377 + }
  378 +
  379 + if (!empty($this->ws_deleted))
  380 + if ($this->deleteParam($expression,$this->ws_deleted)) {
  381 + $msg .= '<li><i>'.$name.'</i> : uses obsolete drived param<br/> '.$expression.'<br/>';
  382 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  383 + $cond_deleted[] = $name;
  384 + continue;
  385 + }
  386 +
  387 + if ($this->deleteParam($expression,array("CDAWEB","MAPSKP","VEXGRAZ","IMPEX"))) {
  388 + $msg .= '<li><i>'.$name.'</i> : uses remote params <br/> '.$expression.'<br/>';
  389 + $cond_deleted[] = $name;
  390 + continue;
  391 + }
  392 +
  393 + $expressionUpdated = $this->updateParams($expression);
  394 + $condObj->expression = $expressionUpdated;
  395 + file_put_contents(NEWUSERPATH.TRANSFERUSER."/REQ/".$id, json_encode($condObj));
  396 + $conditionRoot->appendChild($newRequestXml->importNode($condNode));
  397 + }
  398 +
  399 + $newRequestXml->save($this->newWsDir.'Request.xml');
  400 +
  401 + return array('success' => true, 'msg' => $msg);
  402 + }
140 403  
141   - foreach ($convertedNodes as $item) {
142   - $pairs[$item->getAttribute('oldid')] = $item->getAttribute('xml:id');
143   - }
144   - krsort($pairs, SORT_NATURAL);
145   - $newExp = strtr($expression, $pairs);
146   - $expression = $newExp;
147   -
148   - }
149   -
150   - return $expression;
151   - }
152   -
153   - public function convertArgs($parId, $args){
154   - //TODO arguments.php via Ext.Direct call
155   - $cmd = 'php '.BASE_PATH.'php/arguments.php "'.$parId.'"';
156   -
157   - $arguments = explode(",", $args);
158   - $newArgs = array();
159   -
160   - $res = exec($cmd);
161   -
162   -//TODO just main arguments....
163   - foreach ($arguments as $item) {
164   - if (strpos($item, "/") !== false)
165   - $arg = substr($item,1,strlen($item));
166   - switch ($arg) {
167   - case "black" :
168   - case "blue" :
169   - case "green" :
170   - case "red" :
171   - $newArgs[] = "Color=".$arg;
172   - break;
173   -
174   - case "gsm" :
175   - case "sm" : if (strpos($res, $arg) !== false)
176   - $newArgs[] = "RefFrame=".strtoupper($arg);
177   - break;
178   -
179   - case "log" :
180   - case "lin" : if (strpos($res, $arg) !== false)
181   - $newArgs[] = "Scale=".$arg;
182   - break;
183   - case "cyl" :
184   - $newArgs[] = "OrbitPresentation=".strtoupper($arg);
185   - break;
186   - default :
187   -
188   - }
189   - }
190   -
191   - if (count($arguments) === 0) return "select...";
192   -
193   - if (count($arguments) > 1) return implode("&",$newArgs);
194   -
195   - return $newArgs;
196   - }
197   -
198   - public function createFolders($listName, $nodeType){
199   - // create folders
200   - $folders = $this->ws->getElementsByTagName($listName)->item(0)->getElementsByTagName('level1');
201   - $obj = new stdClass();
202   - foreach ($folders as $folder) {
203   - $obj->leaf = false;
204   - $obj->old_name = "new Folder";
205   - $obj->name = $folder->getAttribute('name');
206   - $obj->parent = $nodeType."-treeRootNode";
207   - $obj->nodeType = $nodeType;
208   -
209   - $this->Mgr->renameObject($obj);
210   - }
211   - }
212   -
213   - public function transferDerived() {
214   -
215   - $msg = '<b>WS (Derived) Params:</b><br/>';
216   - // derived parameters
217   - $this->Mgr = new DerivedParamMgr('derivedParam');
218   - $this->createFolders('paramList','derivedParam');
219   -
220   - // get old params
221   - $wsParams = $this->ws->getElementsByTagName('param');
222   - if ($wsParams->length == 0) {
223   - return array('success' => true, 'msg' => 'No parameters');
224   - }
225   - $obj = new stdClass();
226   - foreach ($wsParams as $param) {
227   - $obj->name = $param->getElementsByTagName('name')->item(0)->nodeValue;
228   - $expression = $param->getElementsByTagName('buildchain')->item(0)->nodeValue;
229   -
230   - if ($this->hasAlias($expression)) {
231   - $newExp = $this->replaceAliases($expression);
232   - $expression = $newExp;
233   - }
234   - if ($this->deleteParam($expression)) {
235   - $msg .= 'deleted name:<b>'.$obj->name.'</b>; expression: '.$expression.'<br/>';
236   - // error_log( 'For INFO : DELETED '.$expression,1,email);
237   - $this->ws_deleted[] = $obj->name;
238   - continue;
239   - }
240   -
241   - $obj->buildchain = $this->updateParams($expression);
242   - $obj->timestep = $param->getElementsByTagName('timestep')->item(0)->nodeValue;
243   - $obj->units = $param->getElementsByTagName('units')->item(0)->nodeValue;
244   - $obj->description = $param->getElementsByTagName('description')->item(0)->nodeValue;
245   - $obj->ytitle = "";
246   - $obj->nodeType = "derivedParam";
247   - $obj->leaf = true;
248   -
249   - $this->Mgr->objectDom = new DomDocument("1.0");
250   - if ($param->parentNode->tagName === 'level1') {
251   - $folder_id = $param->parentNode->getAttribute('id');
252   - $this->Mgr->createObject($obj, $folder_id);
253   - }
254   - else {
255   - $this->Mgr->createObject($obj);
256   - }
257   - }
258   - $msg .= ' ok<br/>';
259   - return array('success' => true, 'msg' => $msg);
260   - }
261   -
262   - public function transferTimeTables() {
263   -
264   - $msg = '<b>Time Tables:</b><br/>';
265   - // time tables
266   - $this->Mgr = new TimeTableMgr();
267   - $this->createFolders('timetabList','timeTable');
268   - $TTdir = OLDUSERPATH.TRANSFERUSER."/TT/";
269   - // get old time tabs
270   - $timeTabs = $this->ws->getElementsByTagName('timetab');
271   -
272   - if ($timeTabs->length == 0) {
273   - return array('success' => true, 'msg' => 'No time tables');
274   - }
275   -
276   - $obj = new stdClass();
277   -
278   - $ttXML = new DomDocument("1.0");
279   - foreach ($timeTabs as $item) {
280   -
281   - $obj->name = $item->getElementsByTagName('name')->item(0)->nodeValue;
282   - $obj->created = $item->getElementsByTagName('created')->item(0)->nodeValue;
283   - $obj->description = $item->getElementsByTagName('condition')->item(0)->nodeValue;
284   - $obj->history = 'From old AMDA';
285   - $obj->nodeType = "timeTable";
286   - $obj->leaf = true;
287   -// intervals
288   - if (!$ttXML->load($TTdir.$obj->name.".xml")) {
289   - $msg .= 'failed to copy '.$obj->name.'<br/>';
290   - continue;
291   - }
292   -
293   - $intervals = $ttXML->getElementsByTagName("Interval");
294   - $ints = array();
295   -
296   - foreach ($intervals as $interval){
297   - $int = new stdClass();
298   - $int->start = $interval->getElementsByTagName("Start")->item(0)->nodeValue;
299   - $int->stop = $interval->getElementsByTagName("Stop")->item(0)->nodeValue;
300   - $ints[] = $int;
301   - }
302   - $obj->nbIntervals = $intervals->length;
303   -
304   - $this->Mgr->objectDom = new DomDocument("1.0");
305   - if ($item->parentNode->tagName === 'level1') {
306   - $folder_id = $item->parentNode->getAttribute('id');
307   - $res = $this->Mgr->createObject($obj, $folder_id);
308   - }
309   - else {
310   - $res = $this->Mgr->createObject($obj);
311   - }
312   -
313   - if ($res['id']) {
314   - $res = $this->Mgr->saveIntervals($res['id'],$ints,'create');
315   - if (!$res['success'])
316   - $msg .= 'failed copy Time Table '. $obj->name.'<br/>';
317   - }
318   - else {
319   - $msg .= 'failed copy Time Table '. $obj->name.'<br/>';
320   - }
321   -
322   - }
323   -
324   - $msg .= ' ok<br/>';
325   -
326   - return array('success' => true, 'msg' => $msg);
327   - }
328   -
329   - public function transferConditions() {
  404 + public function transferMyData()
  405 + {
  406 + $msg = '<b><i>MyData Parameters / My Files:</i></b><br/><br/>';
  407 + $msg.= '<i>Note :</i> CEF format is not implemented<br/><br/>';
  408 +
  409 + if (!$this->oldWs->load($this->oldWsDir.'WsParams.xml')) {
  410 + error_log('cannot load WsParams.xml for '.TRANSFERUSER,1,email);
  411 + return array('success' => false, 'error' => 'Sorry, we failed to get your MyData Params from old AMDA');
  412 + }
  413 +
  414 + if (!file_exists($this->newWsDir.'WsParams.xml'))
  415 + $this->createDom();
  416 + else
  417 + $this->newWs->load($this->newWsDir.'WsParams.xml');
  418 +
  419 + $BaseXml = new DomDocument("1.0");
  420 + $FilesXml = new DomDocument("1.0");
  421 +
  422 + // get old params
  423 + $wsdParamsOld = $this->oldWs->getElementsByTagName('mydata');
  424 +
  425 + if ($wsdParamsOld->length == 0) {
  426 + return array('success' => true, 'msg' => 'You have no MyData parameters');
  427 + }
  428 +
  429 + if (!$BaseXml->load(OLDUSERPATH.TRANSFERUSER.'/DATA/base.xml')) {
  430 + return array('success' => false, 'msg' => 'base description corrupted');
  431 + }
  432 +
  433 + if (!$FilesXml->load($this->oldWsDir.'Files.xml')) {
  434 + return array('success' => false, 'msg' => 'files description corrupted');
  435 + }
  436 +
  437 + $this->newWs->load($this->newWsDir.'WsParams.xml');
  438 + $paramDom = new DomDocument("1.0");
330 439  
331   - $msg = '<b>Conditions:</b><br/>';
332   - // conditons
333   - $this->Mgr = new RequestMgr('condition');
334   - $condDir = OLDUSERPATH.TRANSFERUSER."/REQ/";
335   - // get old conditions
336   - $conditions = glob($condDir."*.cond");
337   -
338   - if (count($conditions) == 0) {
339   - return array('success' => true, 'msg' => 'No conditions');
340   - }
341   -
342   - $obj = new stdClass();
343   - foreach ($conditions as $item) {
344   - $cond = file($item, FILE_IGNORE_NEW_LINES);
345   - $obj->name = substr(basename($item), 0, -5);
346   - $expression = $cond[0];
347   -
348   - if ($this->hasAlias($expression)) {
349   - $newExp = $this->replaceAliases($expression);
350   - $expression = $newExp;
351   - }
352   -
353   - if ($this->deleteParam($expression)) {
354   - $msg .= 'deleted name:<b>'.$obj->name.'</b>; expression:'.$expression.'<br/>';
355   - continue;
356   - }
357   -
358   - $obj->expression = $this->updateParams($expression);
359   - $obj->sampling = $cond[1];
360   - $obj->gap = $cond[2];
361   - $obj->description = "From old AMDA";
362   - $obj->timesrc = "Interval";
363   -
364   - if ($cond[3]) {
365   - $obj->startDate = str_replace(":", "-", substr($cond[3],0,10))."T".substr($cond[3],11,8);
366   - $obj->durationDay = "0".substr($cond[4],0,3);
367   - $obj->durationHour = substr($cond[4],4,2);
368   - $obj->durationMin = substr($cond[4],7,2);
369   - $obj->durationSec = substr($cond[4],10,2);
370   - }
371   - else {
372   - $timestamp = mktime(0, 0, 0, date("m"), date("d")-1, date("Y"));
373   - $obj->startDate = date('Y-m-d\TH:i:s',$timestamp);
374   - $obj->durationDay = "0001";
375   - $obj->durationHour = "00";
376   - $obj->durationMin = "00";
377   - $obj->durationSec = "00";
378   - }
379   -
380   - $obj->nodeType = "condition";
381   - $obj->leaf = true;
382   -
383   - $this->Mgr->createObject($obj);
384   - }
385   -
386   - $msg .= ' ok<br/>';
387   -
388   - return array('success' => true, 'msg' => $msg);
389   - }
390   -
391   - public function transferRequests() {
392   -
393   - $msg = '<b>Requests:</b><br/>';
394   - // requests
395   - $this->Mgr = new RequestMgr('request');
396   - $reqDir = OLDUSERPATH.TRANSFERUSER."/REQ/";
397   - // get old requests
398   - $requests = glob($reqDir."*.xml");
399   -
400   - if (count($requests) == 0) {
401   - return array('success' => true, 'msg' => 'No requests');
402   - }
403   -
404   - $reqXML = new DomDocument("1.0");
405   -
406   - $obj = new stdClass();
407   - foreach ($requests as $item) {
408   -
409   - if (!$reqXML->load($item)) {
410   - $msg .= 'failed to copy '.substr(basename($item), 0, -4).'<br/>';
411   - }
412   - $obj->name = substr(basename($item), 0, -4);
413   - $obj->tabId = 1;
414   - $obj->outputName = '';
415   - $obj->orientation = strtoupper($reqXML->getElementsByTagName('orientation')->item(0)->nodeValue);
416   - $obj->format = 'PNG';
417   - $obj->title = '';
418   - $obj->description = 'From old AMDA';
419   - $obj->charSize = 1.3;
420   - $obj->thickness = 1;
421   - $obj->ppp = 3000;
422   - $obj->forcedLayout = false;
423   - $obj->forcedMulti = false;
424   - $obj->timesrc = 'Interval';
425   - $start = $reqXML->getElementsByTagName('StartTime')->item(0)->nodeValue;
426   - $obj->startDate = str_replace(":", "-", substr($start,0,10))."T".substr($start,11,8);
427   - $tint = $reqXML->getElementsByTagName('TimeInt')->item(0)->nodeValue;
428   - $obj->durationDay = "0".substr($tint,0,3);
429   - $obj->durationHour = substr($tint,4,2);
430   - $obj->durationMin = substr($tint,7,2);
431   - $obj->durationSec = substr($tint,10,2);
432   -// Panels
433   -
434   - $obj->children = array();
435   - $panels = array();
436   -
437   - $params = $reqXML->getElementsByTagName('param');
438   - foreach ($params as $param) {
439   -
440   - $parId = $param->getAttribute('xml:id');
441   -
442   -//check deleted ws_
443   - if ($this->ws_deleted && strtolower(substr($parId,0,3) == "ws_")) {
444   - foreach ($this->ws_deleted as $item) {
445   - if ($item === $parId) {
446   - $msg .= 'ws param deleted '.$parId.'<br/>';
447   - continue 2;
448   - }
449   - }
450   - }
451   -
452   - if (substr($parId,0,3) == "WS_")
453   - $parId = strtolower($parId);
454   -
455   - if ($this->deleteParam($parId, true)) {
456   - $msg .= 'param deleted '.$parId.'<br/>';
457   - continue;
458   - }
459   - $newParId = $this->updateParams($parId, true);
460   - $panelNumber = $param->getAttribute('panel');
461   -//print_r($obj->name." ".$panelNumber.PHP_EOL);
462   -// no such panel -> create
463   - if (!$panels[$panelNumber]) {
464   - $aPanel = new stdClass();
465   - $aPanel->name = 'Panel '.$panelNumber;
466   - $aPanel->leaf = false;
467   - $aPanel->text = 'Panel '.$panelNumber;
468   - $aPanel->width = $param->getAttribute('width');
469   - $aPanel->height = $param->getAttribute('height');
470   - $aPanel->xTitle = "";
471   - $aPanel->xRangeMin = $param->getAttribute('xmin');
472   - $aPanel->xRangeMax = $param->getAttribute('xmax');
473   - $aPanel->y1Title = "";
474   - $aPanel->y1RangeMin = $param->getAttribute('ymin');
475   - $aPanel->y1RangeMax = $param->getAttribute('ymax');
476   - $aPanel->y2Title = "";
477   - $aPanel->y2RangeMin = 0;
478   - $aPanel->y2RangeMax = 0;
479   - $aPanel->plotType = "TIME";
480   - $panels[$panelNumber] = $aPanel;
481   -
482   - $panels[$panelNumber]->children = array();
483   - }
484   -// add parameter to the panel
485   - $aParameter = new stdClass();
486   - $aParameter->name = $newParId;
487   - $aParameter->text = $newParId;
488   - $aParameter->leaf = true;
489   - $aParameter->yaxe = false;
490   -//TODO if we need to check this reallY???
491   - $aParameter->isScatter = false;
492   - $aParameter->needsArgs = false;
493   - if ($param->getAttribute('args') === "")
494   - $aParameter->paramArgs = "select...";
495   - else
496   - $aParameter->paramArgs = $this->convertArgs($newParId, $param->getAttribute('args'));
497   -
498   - $panels[$panelNumber]->children[] = $aParameter;
499   - }
500   -// if there are unordered keys json_encode interprate array as object....
501   - $obj->children = array_values($panels);
502   - $obj->nodeType = "request";
503   - $obj->leaf = true;
504   -
505   - $this->Mgr->createObject($obj).PHP_EOL;
506   - }
507   -
508   - $msg .= ' ok<br/>';
509   -
510   - return array('success' => true, 'msg' => $msg);
511   - }
512   -
513   - public function transferMyData() {
514   -
515   - $msg = '<b>My Data:</b><br/>';
516   -// start with copying DATA dir as it is
517   -
518   - foreach (glob(OLDUSERPATH.TRANSFERUSER.'/DATA/*') as $item) {
519   - if (!copy($item, USERDATADIR.basename($item))) {
520   - error_log('can\'t copy '.$item,1,email);
521   - $msg .= 'failed copy file '.basename($item).'<br/>';
522   - }
523   - }
524   -
525   - $filesXml = new DomDocument("1.0");
526   -
527   - if (!$filesXml->load($this->wsDir.'files.xml')) $msg .= 'no files.xml <br/>';
528   - else {
529   -
530   - $fileMgr = new FilesMgr();
531   - $filesXmlNew = new DomDocument("1.0");
532   - $root = $filesXmlNew->createElement('ws');
533   - $filesXmlNew->appendChild($root);
534   -
535   - $list = $filesXmlNew->createElement("fileList");
536   - $list->setAttribute("xml:id", "myData-treeRootNode");
537   - $root->appendChild($list);
538   -
539   - $files = $filesXml->getElementsByTagName("file");
540   -
541   - $folders = $filesXml->getElementsByTagName("level1");
542   -
543   - if ($folders->length > 0)
544   - foreach ($folders as $folder) {
545   - $newFolder = $filesXmlNew->createElement("folder");
546   - $newFolder->setAttribute("xml:id", $folder->getAttribute("id"));
547   - $newFolder->setAttribute("name", $folder->getAttribute("id"));
548   - $list->appendChild($newFolder);
549   - }
550   -
551   - foreach ($files as $file) {
552   - $newFile = $filesXmlNew->createElement("file", $file->getAttribute("title"));
553   - $newFile->setAttribute("xml:id", $file->getAttribute("id"));
554   - $newFile->setAttribute("name", $file->getAttribute("id"));
555   - $format = $file->getElementsByTagName("format")->item(0)->nodeValue;
556   - $newFile->setAttribute("format", $format);
557   - $newFile->setAttribute("uploaded", $file->getElementsByTagName("uploaded")->item(0)->nodeValue);
558   - $newFile->setAttribute("start", $file->getAttribute("start"));
559   - $newFile->setAttribute("stop", $file->getAttribute("stop"));
560   -// no sampling for cdf in old amda
561   - $minSampling = $file->getAttribute("sampling");
562   - $maxSampling = $file->getAttribute("maxsampling");
563   -
564   - if (!$minSampling) {
565   - $minSampling = $this->getSampling(USERDATADIR.$file->getAttribute("id"), $format);
566   - $maxSampling = $minSampling;
567   - }
568   -
569   - $newFile->setAttribute("minsampling", $minSampling);
570   - $newFile->setAttribute("maxsampling", $maxSampling);
571   -//TODO check mask
572   - $newFile->setAttribute("mask", $file->getAttribute("id"));
573   -
574   - if ($file->parentNode->tagName == 'level1')
575   - $filesXmlNew->getElementById($file->parentNode->getAttribute("id"))->appendChild($newFile);
576   - else
577   - $list->appendChild($newFile);
578   - }
579   - $filesXmlNew->save(USERWSDIR."Files.xml");
580   - }
581   -// mydata parameters
582   - $this->Mgr = new DerivedParamMgr('mydataParam');
583   - $this->createFolders('mydataList','mydataParam');
584   - //TODO folders are they OK?
585   - // get old params
586   - $wsdParams = $this->ws->getElementsByTagName('mydata');
587   -
588   - //TODO vi ??
589   - // $obj = new stdClass();
590   - foreach ($wsdParams as $item) {
591   - $obj = new stdClass();
592   - $obj->name = $item->getElementsByTagName('name')->item(0)->nodeValue;
593   - $obj->nodeType = "myDataParam";
594   - $obj->leaf = true;
595   - $obj->desc = $item->getAttribute('desc');
596   - $obj->file = $item->getAttribute('fileOrig');
597   - $obj->mask = $item->getAttribute('fileMask');
598   - $obj->fillvalue = $item->getAttribute('dataFillValue');
599   - $obj->minsampling = $item->getAttribute('dataSampling');
600   - $obj->maxsampling = $item->getAttribute('maxSampling');
601   - $obj->format = $item->getAttribute('fileFormat');
602   - $obj->type = $item->getAttribute('dataType');
603   - $obj->size = $item->getAttribute('dataSize');
604   - $obj->ytitle = $item->getAttribute('yTitle');
605   - $obj->realvar = $item->getAttribute('realName');
606   - $obj->units = $item->getAttribute('dataUnits');
607   - $obj->legend = $item->getAttribute('dataLegend');
608   -
609   - $this->Mgr->objectDom = new DomDocument("1.0");
610   - if ($item->parentNode->tagName === 'level1') {
611   - $folder_id = $item->parentNode->getAttribute('id');
612   - $this->Mgr->createObject($obj, $folder_id);
613   - }
614   - else {
615   - $this->Mgr->createObject($obj);
616   - }
617   - }
618   -
619   - $msg .= ' ok<br/>';
620   -
621   - return array('success' => true, 'msg' => $msg);
622   - }
  440 + $msg.= ' Not copied parameters : <br/>';
  441 + foreach ($wsdParamsOld as $wsdParamOld) {
  442 + $format = $wsdParamOld->getAttribute('format');
  443 + $name = $wsdParamOld->getAttribute('name');
  444 + $id = $wsdParamOld->getAttribute('xml:id');
  445 + $mask = $wsdParamOld->getAttribute('mask');
  446 + if ($format == 'cef') {
  447 + $deletedVi[] = $mask;
  448 + $msg .= '<li><i>'.$name.'</i><br/>';
  449 + $this->wsd_deleted[] = 'wsd_'.$name;
  450 + }
  451 + else {
  452 + $desc = $wsdParamOld->getAttribute('desc');
  453 + $start = substr($desc,0,16).':00';
  454 + $stop = substr($desc,17).':00';
  455 + $wsdParamOld->setAttribute('desc', $start.'-'.$stop);
  456 +
  457 + $this->newWs->getElementsByTagName('mydataList')->item(0)->appendChild($this->newWs->importNode($wsdParamOld));
  458 +
  459 + $paramDom->load($this->oldWsDir.$id.'.xml');
  460 + $descNode = $paramDom->getElementsByTagName('desc')->item(0);
  461 + $descNode->nodeValue = $start.'-'.$stop;
  462 + $paramDom->save($this->newWsDir.$id.'.xml');
  463 +
  464 + $fileFormat[$mask] = $format === 'txt' ? 'ASCII' : strtoupper($format);
  465 + }
  466 + }
  467 +
  468 + $this->newWs->save($this->newWsDir.'WsParams.xml');
  469 +
  470 + // First delete CEF files
  471 + $xpBase = new domxpath($BaseXml);
  472 + foreach ($deletedVi as $vi) {
  473 + $maskNode = $xpBase->query("//mask[.='".$vi."']");
  474 + if ( $maskNode->length == 0 )
  475 + error_log('No '.$vi.' in '.TRANSFERUSER.'/DATA/base.xml',1,email);
  476 + else {
  477 + $viNode = $maskNode->item(0)->parentNode;
  478 + $viNode->parentNode->removeChild($viNode);
  479 + }
  480 + }
  481 + // Then modify base.xml : xml:id => id
  482 + $viNodes = $BaseXml->getElementsByTagName('vi');
  483 + foreach ($viNodes as $viNode) {
  484 + $id = $viNode->getAttribute('xml:id');
  485 + $viNode->removeAttribute('xml:id');
  486 + $viNode->setAttribute('id',$id);
  487 + $mask = $viNode->getElementsByTagName('mask')->item(0)->nodeValue;
  488 + $viNode->setAttribute('format', $fileFormat[$mask]);
  489 + }
  490 +
  491 + $BaseXml->save(NEWUSERPATH.TRANSFERUSER.'/DATA/base.xml');
  492 +
  493 + $filesNodes = $FilesXml->getElementsByTagName('file');
  494 + foreach ($filesNodes as $file) {
  495 + $fileName = $file->getAttribute('name');
  496 + $format = $file->getAttribute('format');
  497 + if ($format == 'cef') {
  498 + $deletedFiles[] = $file->getAttribute('xml:id');
  499 + }
  500 + else {
  501 + copy(OLDUSERPATH.TRANSFERUSER.'/DATA/'.$fileName,NEWUSERPATH.TRANSFERUSER.'/DATA/'.$fileName);
  502 + }
  503 + }
  504 +
  505 + foreach ($deletedVi as $vi) {
  506 + $node = $FilesXml->getElementById($vi);
  507 + if ($node)
  508 + $node->parentNode->removeChild($node);
  509 + }
  510 + $msg .= 'Not copied files :<br/>';
  511 + foreach ($deletedFiles as $vi) {
  512 + $node = $FilesXml->getElementById($vi);
  513 + if ($node) {
  514 + $msg .= '<li><i>'.$vi.'</i> <br/>';
  515 + $node->parentNode->removeChild($node);
  516 + }
  517 + }
  518 +
  519 + $FilesXml->save($this->newWsDir.'Files.xml');
  520 +
  521 + return array('success' => true, 'msg' => $msg);
  522 + }
  523 +
  524 + public function transferFilters()
  525 + {
  526 + $msg = '<br/><br/><b><i>Filters:</i></b><br/><br/>';
  527 +
  528 + if (!curl_init($this->oldWsDir.'Filters.xml')) {
  529 + return array('success' => true, 'msg' => 'No filters at old AMDA');
  530 + }
  531 +
  532 + $filterXml = new DomDocument("1.0");
  533 + if (!$filterXml->load($this->oldWsDir.'Filters.xml')) {
  534 + return array('success' => false, 'error' => 'Cannot load filters from old AMDA');
  535 + }
  536 +
  537 + $filterXml->save($this->newWsDir.'Filters.xml');
  538 + $msg .= 'Filters have been copied</br>';
  539 + return array('success' => true, 'msg' => $msg);
  540 + }
623 541 }
624 542 ?>
625 543 \ No newline at end of file
... ...