Commit d95e84216543c8f2fde4fc434ffecaa350ad07f9

Authored by Elena.Budnik
1 parent 1dd5504d

ws transfer : initial

js/app/AmdaApp.js
... ... @@ -180,7 +180,6 @@ Ext.define('amdaApp.AmdaApp', {
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 },
... ... @@ -587,12 +586,14 @@ Ext.define('amdaApp.AmdaApp', {
587 586 'MB rests');
588 587 }
589 588  
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 {
  589 + if (isFirstVisit && !isGuest) {
  590 +
  591 + if (isMigration) { // isSpecialInfo
  592 + myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function(module) {
  593 + module.createWindow(isSpecialInfo, 'Welcome on AMDA', true);
  594 + });
  595 + }
  596 + else {
596 597 myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.help.id, true, function(module) {
597 598 module.createWindow();
598 599 });
... ... @@ -601,7 +602,7 @@ Ext.define('amdaApp.AmdaApp', {
601 602 else {
602 603 if (isSpecialInfo && !isNewInfo) {
603 604 myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function(module) {
604   - module.createWindow(isSpecialInfo, 'Welcome to AMDA', true);
  605 + module.createWindow(isSpecialInfo, 'Welcome on AMDA', true);
605 606 });
606 607 }
607 608 }
... ...
js/app/controllers/AboutModule.js
... ... @@ -7,92 +7,121 @@
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 + if (isMigration && isOldWS) {
  83 + win.on({
  84 + show : function(){
  85 + Ext.Msg.show({
  86 + title:'Welcome on new AMDA',
  87 + msg: 'It is your first visit of the new version of AMDA.<br/>'+
  88 + 'Do you want to copy here your workspace from the old AMDA ?',
  89 + buttons: Ext.Msg.YESNO,
  90 + icon: Ext.Msg.QUESTION,
  91 + fn : function (btn) {
  92 + if (btn == 'yes') {
  93 + loadMask.show();
  94 + AmdaAction.convertWS(function(res,e){
  95 + var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
  96 + explorerModule.filtersStore.reload();
  97 + loadMask.hide();
  98 +
  99 + if (res.success == true) {
  100 + myDesktopApp.infoMsg('<b>Your Wokspace has been copied</b><br/><br/> ' +
  101 + '<b>Note : </b><br/><br> Plot Requests have not been copied - too many modifs!<br/>' +
  102 + 'Derived params made from Remote params have not been copied<br/><br/>' + res.msg);
  103 + }
  104 + else {
  105 + myDesktopApp.errorMsg(res.error);
  106 + }
  107 + });
  108 + }
  109 + }
  110 + });
  111 + }
  112 + });
  113 + }
  114 + win.show();
  115 + }
  116 + else if (win.file === theFile) {
  117 + win.toFront();
  118 + }
  119 + else {
  120 + win.loader.url = helpDir + theFile;
  121 + win.loader.load();
  122 + win.setTitle(theTitle);
  123 + win.file = theFile;
  124 + win.toFront();
  125 + }
  126 + }
98 127 });
... ...
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 getNotready() {
  48 +
  49 + $deletedXML = new DomDocument("1.0");
  50 + $deletedXML->load(CONVERSIONDIR."NotReady.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 deleteParam($exp, $deleted)
  61 + {
  62 + $toDelete = false;
  63 +
  64 + foreach ($deleted as $item) {
  65 + if (strpos($exp, $item) !== false) {
  66 + $toDelete = true;
  67 + break;
  68 + }
  69 + }
  70 +
  71 + return $toDelete;
  72 + }
  73 +
  74 + private function getWs($exp)
  75 + {
  76 + $ws = array();
  77 +
  78 + if (strpos($exp, 'ws_') !== false) {
  79 + $arr = $this->delimitIt($exp);
  80 + foreach ($arr as $item) {
  81 + if (strpos($item, 'ws_') !== false)
  82 + $ws[] = substr($item,3);
  83 + }
  84 + return $ws;
  85 + }
  86 + return false;
  87 + }
  88 +
  89 + private function delimitIt($chain) {
49 90  
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');
  91 + $delimiter = '[]+,/*()^<>&|=[-]+';
  92 + $array = split($delimiter,$chain);
  93 + if (trim(end($array)) == "") array_pop($array);
108 94  
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){
  95 + return $array;
  96 + }
127 97  
  98 + private function getModified()
  99 + {
  100 + $convertXML = new DomDocument("1.0");
  101 + $modifiedFile = CONVERSIONDIR.'Modified.xml';
  102 +
  103 + if (!$convertXML->load($modifiedFile))
  104 + error_log('ERROR loading '.$modifiedFile,1,email);
  105 + $convertedNodes = $convertXML->getElementsByTagName('param_convert');
  106 +
  107 + foreach ($convertedNodes as $item) {
  108 + $pairs[$item->getAttribute('oldid')] = $item->getAttribute('xml:id');
  109 + }
  110 + krsort($pairs, SORT_NATURAL);
  111 +
  112 + $this->pairs = $pairs;
  113 + }
  114 +
  115 + private function updateParams($expression)
  116 + {
  117 + $newExp = strtr($expression, $this->pairs);
  118 + $expression = $newExp;
  119 +
  120 + return $expression;
  121 + }
  122 +
  123 + //duplication of FilesMgr method
  124 + public function getSampling($fileName, $format) {
  125 +
  126 + if ($format === 'cdf') {
  127 + copy($fileName, "temp.cdf");
  128 + exec('cdfsamplingfromdata ', $result);
  129 + unlink("temp.cdf");
  130 + $minSamp = $result[count($result)-1];
  131 + }
  132 + else if ($format === 'cef') {
  133 + exec('cefsampling '.$fileName, $result);
  134 + $minSamp = $result[count($result)-1];
  135 + }
  136 + else $minSamp = null;
  137 + //TODO if min & max
  138 + return $minSamp;
  139 + }
  140 +
  141 + protected function createDom()
  142 + {
  143 + $types = array('param' => 'derived', 'mydata' => 'myData');
  144 +
  145 + $rootElement = $this->newWs->createElement('ws');
  146 + foreach ($types as $key => $value)
  147 + {
  148 + $contentId = $value.'Param-treeRootNode';
  149 + $contentTag = $key.'List';
  150 + $typeElement = $this->newWs->createElement($contentTag);
  151 + $typeElement->setAttribute('xml:id', $contentId);
  152 + $rootElement->appendChild($typeElement);
  153 + }
  154 +
  155 + $this->newWs->appendChild($rootElement);
  156 + // $this->newWs->save($this->newWsDir.'WsParams.xml');
  157 + }
  158 +
  159 + public function checkWS()
  160 + {
  161 + // old ws
  162 + if (!curl_init(OLDUSERPATH.TRANSFERUSER)) {
  163 + error_log('no '.TRANSFERUSER.' at old AMDA',1,email);
  164 + return array('success' => false, 'error' => 'Sorry, it seems you have no account at old AMDA');
  165 + }
  166 +
  167 + if (!curl_init($this->oldWsDir)) {
  168 + error_log('no ws.xml for '.TRANSFERUSER,1,email);
  169 + return array('success' => false, 'error' => 'Sorry, we failed to find your workspace at old AMDA');
  170 + }
  171 +
  172 + return array('success' => true);
  173 + }
  174 +
  175 + public function transferDerived()
  176 + {
  177 + $msg = '<b>WS (Derived) Params:</b><br/>';
  178 +
  179 + if (!$this->oldWs->load($this->oldWsDir.'WsParams.xml')) {
  180 + error_log('cannot load WsParams.xml for '.TRANSFERUSER,1,email);
  181 + return array('success' => false, 'error' => 'Sorry, we failed to get your WsParams from old AMDA');
  182 + }
  183 +
  184 + if (!file_exists($this->newWsDir.'WsParams.xml'))
  185 + $this->createDom();
  186 + else
  187 + $this->newWs->load($this->newWsDir.'WsParams.xml');
  188 +
  189 + $deleted = $this->getObsolete();
  190 + $notready = $this->getNotready();
  191 +
  192 + $wsParamNode = $this->newWs->getElementsByTagName('paramList')->item(0);
  193 +
  194 + $wsParamsOld = $this->oldWs->getElementsByTagName('param');
  195 +
  196 + if ($wsParamsOld->length == 0) {
  197 + return array('success' => true, 'msg' => 'No parameters');
  198 + }
  199 +
  200 + $paramXml = new DomDocument("1.0");
  201 + $msg .= '<b>Not copied :</b><br/>';
  202 +
  203 + foreach ($wsParamsOld as $param) {
  204 + $id = $param->getAttribute('xml:id');
  205 + $name = $param->getAttribute('name');
  206 +
  207 + $expression = $param->getAttribute('buildchain');
  208 +
  209 + if ($this->deleteParam($expression,$deleted)) {
  210 + $msg .= '<b>'.$name.'</b> : obsolete <br/> '.$expression.'<br/>';
  211 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  212 + $this->ws_deleted[] = $name;
  213 + continue;
  214 + }
  215 +
  216 + if ($this->deleteParam($expression,$notready)) {
  217 + $msg .= '<b>'.$name.'</b> : not ready yet <br/> '.$expression.'<br/>';
  218 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  219 + $this->ws_deleted[] = $name;
  220 + continue;
  221 + }
  222 +
  223 + if (!empty($this->wsd_deleted))
  224 + if ($this->deleteParam($expression,$this->wsd_deleted)) {
  225 + $msg .= '<b>'.$name.'</b> : uses obsolete myData param<br/> '.$expression.'<br/>';
  226 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  227 + $this->ws_deleted[] = $name;
  228 + continue;
  229 + }
  230 +
  231 + if ($this->deleteParam($expression,array("CDAWEB","MAPSKP","VEXGRAZ","IMPEX"))) {
  232 + $msg .= '<b>'.$name.'</b> : uses remote params <br/> '.$expression.'<br/>';
  233 + $this->ws_deleted[] = $name;
  234 + continue;
  235 + }
  236 +
  237 + $expressionUpdated = $this->updateParams($expression);
  238 + $wsParamNode->appendChild($this->newWs->importNode($param));
  239 +
  240 + $paramXml->load($this->oldWsDir.$id.'.xml');
  241 + $expressionNode = $paramXml->getElementsByTagName('buildchain')->item(0);
  242 + $expressionNode->nodeValue = $expressionUpdated;
  243 + $paramXml->save($this->newWsDir.$id.'.xml');
  244 + }
  245 +
  246 + // check of 'ws bricks' were deleted
  247 + $newParams = $this->newWs->getElementsByTagName('param');
  248 + $xp = new domxpath($this->newWs);
  249 + $paramsToRemove = array();
  250 +
  251 + foreach ($newParams as $param) {
  252 + $id = $param->getAttribute('xml:id');
  253 + $name = $param->getAttribute('name');
  254 +
  255 + $expression = $param->getAttribute('buildchain');
  256 + if ($wsParams = $this->getWs($expression)) {
  257 + foreach ($wsParams as $wsParam) {
  258 + $res = $xp->query("//param[@name='".trim($wsParam)."']");
  259 + if ($res->length == 0) {
  260 + unlink($this->newWsDir.$id.'.xml');
  261 + $paramsToRemove[] = $param;
  262 + $this->ws_deleted[] = $name;
  263 + $msg .= '<b>'.$name.'</b> : uses obsolete / not ready ws param : <br/> '.$expression.'<br/>';
  264 + }
  265 + }
  266 + }
  267 + }
  268 +
  269 + foreach ($paramsToRemove as $paramToRemove) {
  270 + $paramToRemove->parentNode->removeChild($paramToRemove);
  271 + }
  272 +
  273 + $this->newWs->save($this->newWsDir.'WsParams.xml');
  274 + $copied = $newParams->length - count($paramsToRemove);
  275 +
  276 + $msg .= '<br/><b>Copied : </b>'.$copied.' derived parameters<br/><br/>';
  277 + return array('success' => true, 'msg' => $msg);
  278 + }
  279 +
  280 + public function transferTimeTables()
  281 + {
  282 + $msg = '<b>Time Tables:</b><br/>';
  283 +
  284 + // get old time tab list
  285 + $this->newWs->load($this->oldWsDir.'Tt.xml');
  286 + $timeTabs = $this->newWs->getElementsByTagName('timetab');
  287 + if ($timeTabs->length == 0) {
  288 + $msg .= 'No time tables';
  289 + return array('success' => true, 'msg' => $msg);
  290 + }
  291 +
  292 + $oldTtDir = OLDUSERPATH.TRANSFERUSER."/TT/";
  293 + $newTtDir = NEWUSERPATH.TRANSFERUSER."/TT/";
  294 + foreach ($timeTabs as $tab) {
  295 + $id = $tab->getAttribute('xml:id');
  296 + copy($oldTtDir.$id.'.xml', $newTtDir.$id.'.xml');
  297 + }
  298 +
  299 + $this->newWs->save($this->newWsDir.'Tt.xml');
  300 + $msg .= '<b>Copied : </b>'.$timeTabs->length.' time tables<br/><br/>';
  301 + return array('success' => true, 'msg' => $msg);
  302 + }
128 303  
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');
  304 + public function transferConditions()
  305 + {
  306 + $msg = '<b>DataMining Requests</b><br/>';
  307 +
  308 + $oldRequestXml = new DomDocument("1.0");
  309 + $newRequestXml = new DomDocument("1.0");
  310 +
  311 + if (!$oldRequestXml->load($this->oldWsDir.'Request.xml')){
  312 + $msg .= ' cannot copy<br/>';
  313 + return array('success' => true, 'msg' => $msg);
  314 + }
  315 +
  316 + $condNodes = $oldRequestXml->getElementsByTagName('condition');
  317 + if ($condNodes->length == 0) {
  318 + $msg .= ' no DataMining requests to copy<br/>';
  319 + return array('success' => true, 'msg' => $msg);
  320 + }
  321 + $newRequestXml->load($this->newWsDir.'Request.xml');
  322 + $conditionRoot = $newRequestXml->getElementsByTagName('conditionList')->item(0);
  323 +
  324 + $condDir = OLDUSERPATH.TRANSFERUSER."/REQ/";
  325 +
  326 + $deleted = $this->getObsolete();
  327 + $notready = $this->getNotready();
  328 +
  329 + foreach ($condNodes as $condNode) {
  330 + $id = $condNode->getAttribute('xml:id');
  331 + $name = $condNode->getAttribute('name');
  332 + $cond = file($condDir.$id, FILE_IGNORE_NEW_LINES);
  333 +
  334 + $condObj = json_decode($cond[0]);
  335 + $expression = $condObj->expression;
  336 + if ($this->deleteParam($expression, $deleted)) {
  337 + $msg .= '<b>'.$name.'</b> : obsolete <br/> '.$expression.'<br/>';
  338 + $cond_deleted[] = $name;
  339 + continue;
  340 + }
  341 +
  342 + if ($this->deleteParam($expression,$notready)) {
  343 + $msg .= '<b>'.$name.'</b> : not ready yet <br/> '.$expression.'<br/>';
  344 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  345 + $cond_deleted[] = $name;
  346 + continue;
  347 + }
  348 +
  349 + if (!empty($this->wsd_deleted))
  350 + if ($this->deleteParam($expression,$this->wsd_deleted)) {
  351 + $msg .= '<b>'.$name.'</b> : uses obsolete myData param<br/> '.$expression.'<br/>';
  352 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  353 + $cond_deleted[] = $name;
  354 + continue;
  355 + }
  356 +
  357 + if (!empty($this->ws_deleted))
  358 + if ($this->deleteParam($expression,$this->ws_deleted)) {
  359 + $msg .= '<b>'.$name.'</b> : uses obsolete Derived param<br/> '.$expression.'<br/>';
  360 + // error_log( 'For INFO : DELETED '.$expression,1,email);
  361 + $cond_deleted[] = $name;
  362 + continue;
  363 + }
  364 +
  365 + if ($this->deleteParam($expression,array("CDAWEB","MAPSKP","VEXGRAZ","IMPEX"))) {
  366 + $msg .= '<b>'.$name.'</b> : uses remote params <br/> '.$expression.'<br/>';
  367 + $cond_deleted[] = $name;
  368 + continue;
  369 + }
  370 +
  371 + $expressionUpdated = $this->updateParams($expression);
  372 + $condObj->expression = $expressionUpdated;
  373 + file_put_contents(NEWUSERPATH.TRANSFERUSER."/REQ/".$id, json_encode($condObj));
  374 + $conditionRoot->appendChild($newRequestXml->importNode($condNode));
  375 + }
  376 +
  377 + $newRequestXml->save($this->newWsDir.'Request.xml');
  378 + $msg .= ' <br/>';
  379 +
  380 + return array('success' => true, 'msg' => $msg);
  381 + }
140 382  
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() {
330   -
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   - }
  383 + public function transferMyData()
  384 + {
  385 + $msg = '<b>My Data:</b><br/>';
  386 +
  387 + if (!$this->oldWs->load($this->oldWsDir.'WsParams.xml')) {
  388 + error_log('cannot load WsParams.xml for '.TRANSFERUSER,1,email);
  389 + return array('success' => false, 'error' => 'Sorry, we failed to get your MyData Params from old AMDA');
  390 + }
  391 +
  392 + if (!file_exists($this->newWsDir.'WsParams.xml'))
  393 + $this->createDom();
  394 + else
  395 + $this->newWs->load($this->newWsDir.'WsParams.xml');
  396 +
  397 + $BaseXml = new DomDocument("1.0");
  398 + $FilesXml = new DomDocument("1.0");
  399 +
  400 + // get old params
  401 + $wsdParamsOld = $this->oldWs->getElementsByTagName('mydata');
  402 +
  403 + if ($wsdParamsOld->length == 0) {
  404 + return array('success' => true, 'msg' => 'No parameters');
  405 + }
  406 +
  407 + if (!$BaseXml->load(OLDUSERPATH.TRANSFERUSER.'/DATA/base.xml')) {
  408 + return array('success' => false, 'msg' => 'base description corrupted');
  409 + }
  410 +
  411 + if (!$FilesXml->load($this->oldWsDir.'Files.xml')) {
  412 + return array('success' => false, 'msg' => 'files description corrupted');
  413 + }
  414 +
  415 + $this->newWs->load($this->newWsDir.'WsParams.xml');
  416 + $paramDom = new DomDocument("1.0");
  417 +
  418 + foreach ($wsdParamsOld as $wsdParamOld) {
  419 + $format = $wsdParamOld->getAttribute('format');
  420 + $name = $wsdParamOld->getAttribute('name');
  421 + $id = $wsdParamOld->getAttribute('xml:id');
  422 + $mask = $wsdParamOld->getAttribute('mask');
  423 + if ($format == 'cef') {
  424 + $deletedVi[] = $mask;
  425 + $msg .= '<b>'.$name.'</b> : CEF format is not implemented <br/>';
  426 + $this->wsd_deleted[] = 'wsd_'.$name;
  427 + }
  428 + else {
  429 + $desc = $wsdParamOld->getAttribute('desc');
  430 + $start = substr($desc,0,16).':00';
  431 + $stop = substr($desc,17).':00';
  432 + $wsdParamOld->setAttribute('desc', $start.'-'.$stop);
  433 +
  434 + $this->newWs->getElementsByTagName('mydataList')->item(0)->appendChild($this->newWs->importNode($wsdParamOld));
  435 +
  436 + $paramDom->load($this->oldWsDir.$id.'.xml');
  437 + $descNode = $paramDom->getElementsByTagName('desc')->item(0);
  438 + $descNode->nodeValue = $start.'-'.$stop;
  439 + $paramDom->save($this->newWsDir.$id.'.xml');
  440 +
  441 + $fileFormat[$mask] = $format === 'txt' ? 'ASCII' : strtoupper($format);
  442 + }
  443 + }
  444 +
  445 + $this->newWs->save($this->newWsDir.'WsParams.xml');
  446 +
  447 + // First delete CEF files
  448 + $xpBase = new domxpath($BaseXml);
  449 + foreach ($deletedVi as $vi) {
  450 + $maskNode = $xpBase->query("//mask[.='".$vi."']");
  451 + if ( $maskNode->length == 0 )
  452 + error_log('No '.$vi.' in '.TRANSFERUSER.'/DATA/base.xml',1,email);
  453 + else {
  454 + $viNode = $maskNode->item(0)->parentNode;
  455 + $files = $viNode->getElementsByTagName('file');
  456 + foreach ($files as $file) {
  457 + $deletedFiles[] = $file->getAttribute('name');
  458 + }
  459 + $viNode->parentNode->removeChild($viNode);
  460 + }
  461 + }
  462 + // Then modify base.xml : xml:id => id
  463 + $viNodes = $BaseXml->getElementsByTagName('vi');
  464 + foreach ($viNodes as $viNode) {
  465 + $id = $viNode->getAttribute('xml:id');
  466 + $viNode->removeAttribute('xml:id');
  467 + $viNode->setAttribute('id',$id);
  468 + $mask = $viNode->getElementsByTagName('mask')->item(0)->nodeValue;
  469 + $viNode->setAttribute('format', $fileFormat[$mask]);
  470 +
  471 + }
  472 +
  473 + $BaseXml->save(NEWUSERPATH.TRANSFERUSER.'/DATA/base.xml');
  474 +
  475 + $filesNodes = $FilesXml->getElementsByTagName('file');
  476 + foreach ($filesNodes as $file) {
  477 + $fileName = $file->getAttribute('name');
  478 + if (!in_array($fileName,$deletedFiles)) {
  479 + copy(OLDUSERPATH.TRANSFERUSER.'/DATA/'.$fileName,NEWUSERPATH.TRANSFERUSER.'/DATA/'.$fileName);
  480 + }
  481 + }
  482 +
  483 + foreach ($deletedVi as $vi) {
  484 + $node = $FilesXml->getElementById($vi);
  485 + if ($node)
  486 + $node->parentNode->removeChild($node);
  487 + }
  488 +
  489 + $FilesXml->save($this->newWsDir.'Files.xml');
  490 + $msg .= ' ok<br/>';
  491 +
  492 + return array('success' => true, 'msg' => $msg);
  493 + }
  494 +
  495 + public function transferFilters()
  496 + {
  497 + $msg = '<b>Filters:</b><br/>';
  498 +
  499 + if (!curl_init($this->oldWsDir.'Filters.xml')) {
  500 + return array('success' => true, 'msg' => 'No filters at old AMDA');
  501 + }
  502 +
  503 + $filterXml = new DomDocument("1.0");
  504 + if (!$filterXml->load($this->oldWsDir.'Filters.xml')) {
  505 + return array('success' => false, 'error' => 'Cannot load filters from old AMDA');
  506 + }
  507 +
  508 + $filterXml->save($this->newWsDir.'Filters.xml');
  509 + return array('success' => true, 'msg' => '<b>Filters</b> have been copied');
  510 + }
623 511 }
624 512 ?>
625 513 \ No newline at end of file
... ...