BxDataMigrationModule.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <?php
  2. /***************************************************************************
  3. * Dolphin Smart Community Builder
  4. * -------------------
  5. * begin : Mon Mar 23 2006
  6. * copyright : (C) 2007 BoonEx Group
  7. * website : http://www.boonex.com
  8. * This file is part of Dolphin - Smart Community Builder
  9. *
  10. * Dolphin is free software; you can redistribute it and/or modify it under
  11. * the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the
  13. * License, or any later version.
  14. *
  15. * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  16. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. * See the GNU General Public License for more details.
  18. * You should have received a copy of the GNU General Public License along with Dolphin,
  19. * see license.txt file; if not, write to marketing@boonex.com
  20. ***************************************************************************/
  21. bx_import('BxDolModuleDb');
  22. bx_import('BxDolModule');
  23. require_once 'BxCheckerMigration.php';
  24. if ( function_exists('ini_set')) {
  25. ini_set('max_execution_time', 0);
  26. }
  27. define('MIGRATION_SUCCESSFUL', 1);
  28. define('MIGRATION_FAILED', 0);
  29. class BxDataMigrationModule extends BxDolModule
  30. {
  31. // contain some module information ;
  32. var $aModuleInfo;
  33. // contain path for current module;
  34. var $sPathToModule;
  35. var $aMigrationModules;
  36. var $sProcessedModule;
  37. /**
  38. * Class constructor ;
  39. *
  40. * @param : $aModule (array) - contain some information about this module;
  41. * [ id ] - (integer) module's id ;
  42. * [ title ] - (string) module's title ;
  43. * [ vendor ] - (string) module's vendor ;
  44. * [ path ] - (string) path to this module ;
  45. * [ uri ] - (string) this module's URI ;
  46. * [ class_prefix ] - (string) this module's php classes file prefix ;
  47. * [ db_prefix ] - (string) this module's Db tables prefix ;
  48. * [ date ] - (string) this module's date installation ;
  49. */
  50. function BxDataMigrationModule(&$aModule)
  51. {
  52. parent::BxDolModule($aModule);
  53. // prepare the location link ;
  54. $this -> sPathToModule = BX_DOL_URL_ROOT . $this -> _oConfig -> getBaseUri();
  55. $this -> aModuleInfo = $aModule;
  56. $this -> aMigrationModules = array(
  57. 'profiles' => array(
  58. 'is_module' => false,
  59. 'module_name' => 'profiles',
  60. 'module_class' => '',
  61. 'migration_class' => 'BxDataMigrationProfiles',
  62. 'dependencies' => array(
  63. ),
  64. ),
  65. 'poll' => array(
  66. 'is_module' => true,
  67. 'module_name' => 'poll',
  68. 'module_class' => 'BxPollModule',
  69. 'migration_class' => 'BxDataMigrationPoll',
  70. 'dependencies' => array(
  71. 'profiles',
  72. ),
  73. ),
  74. 'events' => array(
  75. 'is_module' => true,
  76. 'module_name' => 'events',
  77. 'module_class' => 'BxEventsModule',
  78. 'migration_class' => 'BxDataMigrationEvents',
  79. 'dependencies' => array(
  80. 'profiles',
  81. 'photos',
  82. ),
  83. ),
  84. 'blogs' => array(
  85. 'is_module' => true,
  86. 'module_name' => 'blogs',
  87. 'module_class' => 'BxBlogsModule',
  88. 'migration_class' => 'BxDataMigrationBlogs',
  89. 'dependencies' => array(
  90. 'profiles',
  91. ),
  92. ),
  93. 'ads' => array(
  94. 'is_module' => true,
  95. 'module_name' => 'ads',
  96. 'module_class' => 'BxAdsModule',
  97. 'migration_class' => 'BxDataMigrationAds',
  98. 'dependencies' => array(
  99. 'profiles',
  100. ),
  101. ),
  102. 'news' => array(
  103. 'is_module' => true,
  104. 'module_name' => 'news',
  105. 'module_class' => 'BxNewsModule',
  106. 'migration_class' => 'BxDataMigrationNews',
  107. 'dependencies' => array(
  108. 'profiles',
  109. ),
  110. ),
  111. 'articles' => array(
  112. 'is_module' => true,
  113. 'module_name' => 'articles',
  114. 'module_class' => 'BxArlModule',
  115. 'migration_class' => 'BxDataMigrationArticles',
  116. 'dependencies' => array(
  117. 'profiles',
  118. ),
  119. ),
  120. 'feedback' => array(
  121. 'is_module' => true,
  122. 'module_name' => 'feedback',
  123. 'module_class' => 'BxFdbModule',
  124. 'migration_class' => 'BxDataMigrationFeedback',
  125. 'dependencies' => array(
  126. 'profiles',
  127. ),
  128. ),
  129. 'sounds' => array(
  130. 'is_module' => true,
  131. 'module_name' => 'sounds',
  132. 'module_class' => 'BxSoundsModule',
  133. 'migration_class' => 'BxDataMigrationSounds',
  134. 'dependencies' => array(
  135. 'profiles',
  136. ),
  137. ),
  138. 'photos' => array(
  139. 'is_module' => true,
  140. 'module_name' => 'photos',
  141. 'module_class' => 'BxPhotosModule',
  142. 'migration_class' => 'BxDataMigrationPhotos',
  143. 'dependencies' => array(
  144. 'profiles',
  145. ),
  146. ),
  147. 'videos' => array(
  148. 'is_module' => true,
  149. 'module_name' => 'videos',
  150. 'module_class' => 'BxVideosModule',
  151. 'migration_class' => 'BxDataMigrationVideos',
  152. 'dependencies' => array(
  153. 'profiles',
  154. ),
  155. ),
  156. 'forum' => array(
  157. 'is_module' => true,
  158. 'module_name' => 'forum',
  159. 'module_class' => 'Orca Forum',
  160. 'migration_class' => 'BxDataMigrationForum',
  161. 'dependencies' => array(
  162. 'profiles',
  163. ),
  164. ),
  165. 'acl_levels' => array(
  166. 'is_module' => false,
  167. 'module_name' => 'acl_levels',
  168. 'module_class' => '',
  169. 'migration_class' => 'BxDataMigrationMembership',
  170. 'dependencies' => array(
  171. 'profiles',
  172. ),
  173. ),
  174. 'custom_profile_fields' => array(
  175. 'is_module' => false,
  176. 'module_name' => 'custom_profile_fields',
  177. 'module_class' => '',
  178. 'migration_class' => 'BxDataMigrationProfilesCustomFields',
  179. 'dependencies' => array(
  180. 'profiles',
  181. ),
  182. ),
  183. 'groups' => array(
  184. 'is_module' => true,
  185. 'module_name' => 'groups',
  186. 'module_class' => 'BxGroupsModule',
  187. 'migration_class' => 'BxDataMigrationGroups',
  188. 'dependencies' => array(
  189. 'profiles',
  190. 'photos',
  191. ),
  192. ),
  193. );
  194. }
  195. /**
  196. * Function will get migration from recived modules;
  197. * @return unknown_type
  198. */
  199. function actionMigration($sModule = '')
  200. {
  201. // define the module;
  202. if( isset($this -> aMigrationModules[$sModule]) && $this -> _oDb -> getExtraParam('is_configured') ) {
  203. // trasnfer status;
  204. $sTransferred = $this -> _oDb -> getTransferStatus($sModule);
  205. if( $sTransferred == 'finished' || $sTransferred == 'not_started' ) {
  206. echo MsgBox( _t('_bx_data_migration_already_transfer', $sModule) );
  207. exit;
  208. }
  209. else {
  210. // check module dependencies;
  211. if( isset($this -> aMigrationModules[$sModule]['dependencies'])
  212. && $this -> aMigrationModules[$sModule]['dependencies']) {
  213. foreach($this -> aMigrationModules[$sModule]['dependencies'] as $iKey => $sDependenciesModule)
  214. {
  215. $sTransferred = $this -> _oDb -> getTransferStatus($sDependenciesModule);
  216. if( $sTransferred != 'finished') {
  217. echo MsgBox( _t('_bx_data_migration_install_before', $sDependenciesModule) );
  218. exit;
  219. }
  220. }
  221. }
  222. // create new transfer;
  223. $sTransferResult = $this -> _oDb -> checkTransfer($sModule);
  224. if( !$sTransferResult || $sTransferResult == 'error' ) {
  225. if($sTransferResult == 'error') {
  226. $this -> _oDb -> deleteTransfer($sModule);
  227. }
  228. $this -> _oDb -> createTransfer($sModule);
  229. echo MsgBox( _t('_bx_data_migration_start_transfer') );
  230. }
  231. else {
  232. echo MsgBox( _t('_bx_data_migration_install_started', $sModule) );
  233. }
  234. }
  235. }
  236. else {
  237. echo MsgBox( _t('_bx_data_migration_module_not_defined') );
  238. }
  239. }
  240. /**
  241. * Function will transfer data;
  242. *
  243. * @return : void;
  244. */
  245. function transferData()
  246. {
  247. $sModule = $this -> _oDb -> getFirstTransfer();
  248. // define the module;
  249. if( $sModule && isset($this -> aMigrationModules[$sModule])
  250. && $this -> _oDb -> getExtraParam('is_configured') ) {
  251. // create new module's instance;
  252. require_once($this -> aMigrationModules[$sModule]['migration_class'] . '.php');
  253. $oDolModule = '';
  254. // create module instance;
  255. if($this -> aMigrationModules[$sModule]['module_class']) {
  256. $oDolModule = BxDolModule::getInstance($this -> aMigrationModules[$sModule]['name']);
  257. }
  258. $this -> sProcessedModule = $sModule;
  259. // set as started;
  260. $this -> _oDb -> updateTransferStatus($sModule, 'started');
  261. // create new migration instance;
  262. $oModule = & new $this -> aMigrationModules[$sModule]['migration_class']( $this
  263. , $this -> _oDb -> oldDbConnect(), $oDolModule);
  264. // get migration;
  265. $iOperation = $oModule -> getMigration();
  266. if( $iOperation == MIGRATION_SUCCESSFUL) {
  267. //set as finished;
  268. //$this -> _oDb -> updateTransferStatus($sModule, 'not_started');
  269. $this -> _oDb -> updateTransferStatus($sModule, 'finished');
  270. }
  271. else {
  272. // set as error;
  273. $this -> _oDb -> updateTransferStatus($sModule, 'error');
  274. }
  275. }
  276. }
  277. /**
  278. * Function will generate the poll's admin page ;
  279. *
  280. * @return : (text) - Html presentation data ;
  281. */
  282. function actionAdministration($sAction = '')
  283. {
  284. $GLOBALS['iAdminPage'] = 1;
  285. if( !isAdmin() ) {
  286. header('location: ' . BX_DOL_URL_ROOT);
  287. }
  288. // get all needed css files;
  289. $this -> _oTemplate-> pageCodeAdminStart();
  290. echo $this -> _oTemplate -> addCss('forms_adv.css', true);
  291. $aMenu = array(
  292. 'data_migration' => array('title' => _t('_bx_data_migration'), 'href' => $this -> sPathToModule . 'administration'),
  293. 'set_config' => array('title' => _t('_bx_data_migration_set_config'), 'href' => $this -> sPathToModule . 'administration/settings'),
  294. );
  295. $sPageContent = '';
  296. $sPageTitle = '';
  297. switch ($sAction) {
  298. case 'settings':
  299. $aMenu['set_config']['active'] = 1;
  300. $sPageTitle = _t('_bx_data_migration_configure');
  301. $sPageContent = $this -> _oTemplate -> getConfigForm($this);
  302. break;
  303. default :
  304. if( !$this -> _oDb -> getExtraParam('is_configured') ) {
  305. $aMenu['set_config']['active'] = 1;
  306. $sPageTitle = _t('_bx_data_migration_configure');
  307. $sPageContent = $this -> _oTemplate -> getConfigForm($this);
  308. }
  309. else {
  310. $aMenu['data_migration']['active'] = 1;
  311. // get modules page;
  312. $sPageTitle = _t('_bx_data_migration_choose_data');
  313. $sPageContent = $this -> getModulesList();
  314. }
  315. break;
  316. }
  317. echo $this -> _oTemplate -> adminBlock ($sPageContent, $sPageTitle, $aMenu);
  318. $this -> _oTemplate->pageCodeAdmin( _t('_bx_data_migration_module') );
  319. }
  320. /**
  321. * Function will generate list of allowed modules;
  322. *
  323. * @return : (text) - html presentation data;
  324. */
  325. function getModulesList()
  326. {
  327. $aProccessed = array();
  328. $aStatusTexts = array();
  329. $aLanguageKeys = array(
  330. 'in_procces' => _t('_bx_data_migration_in_process'),
  331. 'transferred' => _t('_bx_data_migration_transferred'),
  332. 'error_transfer' => _t('_bx_data_migration_error_transferred'),
  333. 'queued' => _t('_bx_data_migration_not_started'),
  334. );
  335. // check all modules;
  336. foreach($this -> aMigrationModules as $sModule => $aItems)
  337. {
  338. // define the transfer status;
  339. $sTransferStatus = $this -> _oDb -> getTransferStatus($aItems['module_name']);
  340. $sTransferStatusText = $this -> _oDb -> getTransferStatusText($aItems['module_name']);
  341. if($sTransferStatusText) {
  342. $aStatusTexts[$aItems['module_name']] = $sTransferStatusText;
  343. }
  344. else if($sTransferStatus){
  345. $aStatusTexts[$aItems['module_name']] = $aLanguageKeys['in_procces'];
  346. }
  347. switch($sTransferStatus) {
  348. case 'not_started' :
  349. $sModuleTransferred = ' (' . $aLanguageKeys['queued'] . ') ';
  350. break;
  351. case 'finished' :
  352. $sModuleTransferred = ' (' . $aLanguageKeys['transferred'] . ') ';
  353. break;
  354. case 'started' :
  355. $sModuleTransferred = ' (' . $aLanguageKeys['in_procces'] . ') ';
  356. break;
  357. case 'error' :
  358. $sModuleTransferred = ' (' . $aLanguageKeys['error_transfer'] . ') ';
  359. break;
  360. default :
  361. $sModuleTransferred = '';
  362. }
  363. if($aItems['is_module'] && $aItems['module_name']) {
  364. // check allowed module;
  365. if( $this -> _oDb -> isModule($aItems['module_name']) ){
  366. $aProccessed[ $aItems['module_name'] ] = $aItems['module_name'] . $sModuleTransferred;
  367. }
  368. }
  369. if( !$aItems['is_module'] ) {
  370. $aProccessed[ $sModule ] = $sModule . $sModuleTransferred;;
  371. }
  372. }
  373. return $this -> _oTemplate -> getModulesList($aProccessed, $aStatusTexts, $this);
  374. }
  375. /**
  376. * Function will create new config;
  377. *
  378. * @param : $sPath (string) - path to old dolphin;
  379. * @return : (string) - call back message;
  380. */
  381. function createConfig($sPath)
  382. {
  383. $isDbDefined = false;
  384. $isDirDefined = false;
  385. $sPath = stripslashes($sPath);
  386. if ( substr($sPath, strlen($sPath) - 1 ) != DIRECTORY_SEPARATOR ) {
  387. $sPath .= DIRECTORY_SEPARATOR;
  388. }
  389. // get all seeting from file;
  390. $sDataFile = file_get_contents($sPath . 'inc' . DIRECTORY_SEPARATOR . 'header.inc.php');
  391. $aConfig = array();
  392. // get db values;
  393. $aDbValues = array();
  394. preg_match_all("/db\[\'([a-z]+)\'\].+=.+\'(.*)\'/Ui", $sDataFile, $aDbValues);
  395. if( is_array($aDbValues) ) {
  396. foreach($aDbValues[1] as $iKey => $sParamName)
  397. {
  398. $aConfig[$sParamName] = $aDbValues[2][$iKey];
  399. $isDbDefined = true;
  400. }
  401. }
  402. // get Dir values;
  403. $aDirValues = array();
  404. preg_match_all("/dir\[\'([a-z]+)\'\].+=.+\"(.*)\"/Ui", $sDataFile, $aDirValues);
  405. $sRootDir = '';
  406. $sRootDirInc = '';
  407. if( is_array($aDirValues) ) {
  408. foreach($aDirValues[1] as $iKey => $sParamName)
  409. {
  410. $aConfig[$sParamName] = $aDirValues[2][$iKey];
  411. if($sParamName == 'root') {
  412. $sRootDir = $aDirValues[2][$iKey];
  413. }
  414. if($sParamName == 'classes') {
  415. $sRootDirInc = $aDirValues[2][$iKey];
  416. }
  417. $isDirDefined = true;
  418. }
  419. }
  420. // replace with value;
  421. if($isDirDefined && $isDbDefined) {
  422. foreach($aConfig as $sKey => $sParamName)
  423. {
  424. $aConfig[$sKey] = str_replace('{$dir[\'root\']}', $sRootDir, $aConfig[$sKey]);
  425. $aConfig[$sKey] = str_replace('{$dir[\'inc\']}', $sRootDir . 'inc/', $aConfig[$sKey]);
  426. $this -> _oDb -> createConfig( array('config_' . $sKey => $aConfig[$sKey]) );
  427. }
  428. $this -> _oDb -> createConfig( array('is_configured' => 'yes') );
  429. }
  430. else {
  431. return MsgBox( _t('_bx_data_migration_was_not_defined') );
  432. }
  433. return MsgBox( _t('_bx_data_migration_was_defined') );
  434. }
  435. }