PageRenderTime 26ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/vtlib/Vtiger/PackageImport.php

https://bitbucket.org/thomashii/vtigercrm-6-for-postgresql
PHP | 757 lines | 474 code | 90 blank | 193 comment | 101 complexity | 3ac091696465982fd096a017b612d29b MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-2.0, GPL-3.0
  1. <?php
  2. /*+**********************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. ************************************************************************************/
  10. include_once('vtlib/Vtiger/PackageExport.php');
  11. include_once('vtlib/Vtiger/Unzip.php');
  12. include_once('vtlib/Vtiger/Module.php');
  13. include_once('vtlib/Vtiger/Event.php');
  14. include_once('vtlib/Vtiger/Cron.php');
  15. /**
  16. * Provides API to import module into vtiger CRM
  17. * @package vtlib
  18. */
  19. class Vtiger_PackageImport extends Vtiger_PackageExport {
  20. /**
  21. * Module Meta XML File (Parsed)
  22. * @access private
  23. */
  24. var $_modulexml;
  25. /**
  26. * Module Fields mapped by [modulename][fieldname] which
  27. * will be used to create customviews.
  28. * @access private
  29. */
  30. var $_modulefields_cache = Array();
  31. /**
  32. * License of the package.
  33. * @access private
  34. */
  35. var $_licensetext = false;
  36. /**
  37. * Constructor
  38. */
  39. function Vtiger_PackageImport() {
  40. parent::__construct();
  41. }
  42. /**
  43. * Parse the manifest file
  44. * @access private
  45. */
  46. function __parseManifestFile($unzip) {
  47. $manifestfile = $this->__getManifestFilePath();
  48. $unzip->unzip('manifest.xml', $manifestfile);
  49. $this->_modulexml = simplexml_load_file($manifestfile);
  50. unlink($manifestfile);
  51. }
  52. /**
  53. * Get type of package (as specified in manifest)
  54. */
  55. function type() {
  56. if(!empty($this->_modulexml) && !empty($this->_modulexml->type)) {
  57. return $this->_modulexml->type;
  58. }
  59. return false;
  60. }
  61. /**
  62. * XPath evaluation on the root module node.
  63. * @param String Path expression
  64. */
  65. function xpath($path) {
  66. return $this->_modulexml->xpath($path);
  67. }
  68. /**
  69. * Get the value of matching path (instead of complete xpath result)
  70. * @param String Path expression for which value is required
  71. */
  72. function xpath_value($path) {
  73. $xpathres = $this->xpath($path);
  74. foreach($xpathres as $pathkey=>$pathvalue) {
  75. if($pathkey == $path) return $pathvalue;
  76. }
  77. return false;
  78. }
  79. /**
  80. * Are we trying to import language package?
  81. */
  82. function isLanguageType($zipfile =null) {
  83. if(!empty($zipfile)) {
  84. if(!$this->checkZip($zipfile)) {
  85. return false;
  86. }
  87. }
  88. $packagetype = $this->type();
  89. if($packagetype) {
  90. $lcasetype = strtolower($packagetype);
  91. if($lcasetype == 'language') return true;
  92. }
  93. return false;
  94. }
  95. /**
  96. * checks whether a package is module bundle or not.
  97. * @param String $zipfile - path to the zip file.
  98. * @return Boolean - true if given zipfile is a module bundle and false otherwise.
  99. */
  100. function isModuleBundle($zipfile = null) {
  101. // If data is not yet available
  102. if(!empty($zipfile)) {
  103. if(!$this->checkZip($zipfile)) {
  104. return false;
  105. }
  106. }
  107. return (boolean)$this->_modulexml->modulebundle;
  108. }
  109. /**
  110. * @return Array module list available in the module bundle.
  111. */
  112. function getAvailableModuleInfoFromModuleBundle() {
  113. $list = (Array)$this->_modulexml->modulelist;
  114. return (Array)$list['dependent_module'];
  115. }
  116. /**
  117. * Get the license of this package
  118. * NOTE: checkzip should have been called earlier.
  119. */
  120. function getLicense() {
  121. return $this->_licensetext;
  122. }
  123. /**
  124. * Check if zipfile is a valid package
  125. * @access private
  126. */
  127. function checkZip($zipfile) {
  128. $unzip = new Vtiger_Unzip($zipfile);
  129. $filelist = $unzip->getList();
  130. $manifestxml_found = false;
  131. $languagefile_found = false;
  132. $vtigerversion_found = false;
  133. $modulename = null;
  134. $language_modulename = null;
  135. foreach($filelist as $filename=>$fileinfo) {
  136. $matches = Array();
  137. preg_match('/manifest.xml/', $filename, $matches);
  138. if(count($matches)) {
  139. $manifestxml_found = true;
  140. $this->__parseManifestFile($unzip);
  141. $modulename = $this->_modulexml->name;
  142. $isModuleBundle = (string)$this->_modulexml->modulebundle;
  143. if($isModuleBundle === 'true' && (!empty($this->_modulexml)) &&
  144. (!empty($this->_modulexml->dependencies)) &&
  145. (!empty($this->_modulexml->dependencies->vtiger_version))) {
  146. $languagefile_found = true;
  147. break;
  148. }
  149. // Do we need to check the zip further?
  150. if($this->isLanguageType()) {
  151. $languagefile_found = true; // No need to search for module language file.
  152. break;
  153. } else {
  154. continue;
  155. }
  156. }
  157. // Language file present in en_us folder
  158. $pattern = '/languages\/en_us\/([^\/]+).php/';
  159. preg_match($pattern, $filename, $matches);
  160. if(count($matches)) { $language_modulename = $matches[1]; }
  161. // or Language file may be present in en_us/Settings folder
  162. $settingsPattern = '/languages\/en_us\/Settings\/([^\/]+).php/';
  163. preg_match($settingsPattern, $filename, $matches);
  164. if(count($matches)) { $language_modulename = $matches[1]; }
  165. }
  166. // Verify module language file.
  167. if(!empty($language_modulename) && $language_modulename == $modulename) {
  168. $languagefile_found = true;
  169. }
  170. if(!empty($this->_modulexml) &&
  171. !empty($this->_modulexml->dependencies) &&
  172. !empty($this->_modulexml->dependencies->vtiger_version)) {
  173. $vtigerVersion = (string)$this->_modulexml->dependencies->vtiger_version;
  174. if(version_compare($vtigerVersion, '6.0.0rc', '>=') === true) {
  175. $vtigerversion_found = true;
  176. }
  177. }
  178. $validzip = false;
  179. if($manifestxml_found && $languagefile_found && $vtigerversion_found)
  180. $validzip = true;
  181. if($validzip) {
  182. if(!empty($this->_modulexml->license)) {
  183. if(!empty($this->_modulexml->license->inline)) {
  184. $this->_licensetext = $this->_modulexml->license->inline;
  185. } else if(!empty($this->_modulexml->license->file)) {
  186. $licensefile = $this->_modulexml->license->file;
  187. $licensefile = "$licensefile";
  188. if(!empty($filelist[$licensefile])) {
  189. $this->_licensetext = $unzip->unzip($licensefile);
  190. } else {
  191. $this->_licensetext = "Missing $licensefile!";
  192. }
  193. }
  194. }
  195. }
  196. if($unzip) $unzip->close();
  197. return $validzip;
  198. }
  199. /**
  200. * Get module name packaged in the zip file
  201. * @access private
  202. */
  203. function getModuleNameFromZip($zipfile) {
  204. if(!$this->checkZip($zipfile)) return null;
  205. return (string)$this->_modulexml->name;
  206. }
  207. /**
  208. * returns the name of the module.
  209. * @return String - name of the module as given in manifest file.
  210. */
  211. function getModuleName() {
  212. return (string)$this->_modulexml->name;
  213. }
  214. /**
  215. * Cache the field instance for re-use
  216. * @access private
  217. */
  218. function __AddModuleFieldToCache($moduleInstance, $fieldname, $fieldInstance) {
  219. $this->_modulefields_cache["$moduleInstance->name"]["$fieldname"] = $fieldInstance;
  220. }
  221. /**
  222. * Get field instance from cache
  223. * @access private
  224. */
  225. function __GetModuleFieldFromCache($moduleInstance, $fieldname) {
  226. return $this->_modulefields_cache["$moduleInstance->name"]["$fieldname"];
  227. }
  228. /**
  229. * Initialize Import
  230. * @access private
  231. */
  232. function initImport($zipfile, $overwrite) {
  233. $module = $this->getModuleNameFromZip($zipfile);
  234. if($module != null) {
  235. $unzip = new Vtiger_Unzip($zipfile, $overwrite);
  236. // Unzip selectively
  237. $unzip->unzipAllEx( ".",
  238. Array(
  239. // Include only file/folders that need to be extracted
  240. 'include' => Array('templates', "modules/$module", 'cron', 'languages',
  241. 'settings/actions', 'settings/views', 'settings/models', 'settings/templates'),
  242. // NOTE: If excludes is not given then by those not mentioned in include are ignored.
  243. ),
  244. // What files needs to be renamed?
  245. Array(
  246. // Templates folder
  247. 'templates' => "layouts/vlayout/modules/$module",
  248. // Cron folder
  249. 'cron' => "cron/modules/$module",
  250. // Settings folder
  251. 'settings/actions' => "modules/Settings/$module/actions",
  252. 'settings/views' => "modules/Settings/$module/views",
  253. 'settings/models' => "modules/Settings/$module/models",
  254. // Settings templates folder
  255. 'settings/templates' => "layouts/vlayout/modules/Settings/$module"
  256. )
  257. );
  258. if($unzip) $unzip->close();
  259. }
  260. return $module;
  261. }
  262. function getTemporaryFilePath($filepath=false) {
  263. return 'cache/'. $filepath;
  264. }
  265. /**
  266. * Get dependent version
  267. * @access private
  268. */
  269. function getDependentVtigerVersion() {
  270. return $this->_modulexml->dependencies->vtiger_version;
  271. }
  272. /**
  273. * Get dependent Maximum version
  274. * @access private
  275. */
  276. function getDependentMaxVtigerVersion() {
  277. return $this->_modulexml->dependencies->vtiger_max_version;
  278. }
  279. /**
  280. * Get package version
  281. * @access private
  282. */
  283. function getVersion() {
  284. return $this->_modulexml->version;
  285. }
  286. /**
  287. * Import Module from zip file
  288. * @param String Zip file name
  289. * @param Boolean True for overwriting existing module
  290. *
  291. * @todo overwrite feature is not functionally currently.
  292. */
  293. function import($zipfile, $overwrite=false) {
  294. $module = $this->getModuleNameFromZip($zipfile);
  295. if($module != null) {
  296. // If data is not yet available
  297. if(empty($this->_modulexml)) {
  298. $this->__parseManifestFile($unzip);
  299. }
  300. $buildModuleArray = array();
  301. $installSequenceArray = array();
  302. $moduleBundle = (boolean)$this->_modulexml->modulebundle;
  303. if($moduleBundle == true) {
  304. $moduleList = (Array)$this->_modulexml->modulelist;
  305. foreach($moduleList as $moduleInfos) {
  306. foreach($moduleInfos as $moduleInfo) {
  307. $moduleInfo = (Array)$moduleInfo;
  308. $buildModuleArray[] = $moduleInfo;
  309. $installSequenceArray[] = $moduleInfo['install_sequence'];
  310. }
  311. }
  312. sort($installSequenceArray);
  313. $unzip = new Vtiger_Unzip($zipfile);
  314. $unzip->unzipAllEx($this->getTemporaryFilePath());
  315. foreach ($installSequenceArray as $sequence) {
  316. foreach ($buildModuleArray as $moduleInfo) {
  317. if($moduleInfo['install_sequence'] == $sequence) {
  318. $this->import($this->getTemporaryFilePath($moduleInfo['filepath']), $overwrite);
  319. }
  320. }
  321. }
  322. } else {
  323. $module = $this->initImport($zipfile, $overwrite);
  324. // Call module import function
  325. $this->import_Module();
  326. }
  327. }
  328. }
  329. /**
  330. * Import Module
  331. * @access private
  332. */
  333. function import_Module() {
  334. $tabname = $this->_modulexml->name;
  335. $tablabel= $this->_modulexml->label;
  336. $parenttab=(string)$this->_modulexml->parent;
  337. $tabversion=$this->_modulexml->version;
  338. $isextension= false;
  339. if(!empty($this->_modulexml->type)) {
  340. $type = strtolower($this->_modulexml->type);
  341. if($type == 'extension' || $type == 'language')
  342. $isextension = true;
  343. }
  344. $vtigerMinVersion = $this->_modulexml->dependencies->vtiger_version;
  345. $vtigerMaxVersion = $this->_modulexml->dependencies->vtiger_max_version;
  346. $moduleInstance = new Vtiger_Module();
  347. $moduleInstance->name = $tabname;
  348. $moduleInstance->label= $tablabel;
  349. $moduleInstance->parent=$parenttab;
  350. $moduleInstance->isentitytype = ($isextension != true);
  351. $moduleInstance->version = (!$tabversion)? 0 : $tabversion;
  352. $moduleInstance->minversion = (!$vtigerMinVersion)? false : $vtigerMinVersion;
  353. $moduleInstance->maxversion = (!$vtigerMaxVersion)? false : $vtigerMaxVersion;
  354. $moduleInstance->save();
  355. if(!empty($parenttab)) {
  356. $menuInstance = Vtiger_Menu::getInstance($parenttab);
  357. $menuInstance->addModule($moduleInstance);
  358. }
  359. $this->import_Tables($this->_modulexml);
  360. $this->import_Blocks($this->_modulexml, $moduleInstance);
  361. $this->import_CustomViews($this->_modulexml, $moduleInstance);
  362. $this->import_SharingAccess($this->_modulexml, $moduleInstance);
  363. $this->import_Events($this->_modulexml, $moduleInstance);
  364. $this->import_Actions($this->_modulexml, $moduleInstance);
  365. $this->import_RelatedLists($this->_modulexml, $moduleInstance);
  366. $this->import_CustomLinks($this->_modulexml, $moduleInstance);
  367. $this->import_CronTasks($this->_modulexml);
  368. Vtiger_Module::fireEvent($moduleInstance->name,
  369. Vtiger_Module::EVENT_MODULE_POSTINSTALL);
  370. $moduleInstance->initWebservice();
  371. }
  372. /**
  373. * Import Tables of the module
  374. * @access private
  375. */
  376. function import_Tables($modulenode) {
  377. if(empty($modulenode->tables) || empty($modulenode->tables->table)) return;
  378. /**
  379. * Record the changes in schema file
  380. */
  381. $schemafile = fopen("modules/$modulenode->name/schema.xml", 'w');
  382. if($schemafile) {
  383. fwrite($schemafile, "<?xml version='1.0'?>\n");
  384. fwrite($schemafile, "<schema>\n");
  385. fwrite($schemafile, "\t<tables>\n");
  386. }
  387. // Import the table via queries
  388. foreach($modulenode->tables->table as $tablenode) {
  389. $tablename = $tablenode->name;
  390. $tablesql = "$tablenode->sql"; // Convert to string format
  391. // Save the information in the schema file.
  392. fwrite($schemafile, "\t\t<table>\n");
  393. fwrite($schemafile, "\t\t\t<name>$tablename</name>\n");
  394. fwrite($schemafile, "\t\t\t<sql><![CDATA[$tablesql]]></sql>\n");
  395. fwrite($schemafile, "\t\t</table>\n");
  396. // Avoid executing SQL that will DELETE or DROP table data
  397. if(Vtiger_Utils::IsCreateSql($tablesql)) {
  398. if(!Vtiger_Utils::checkTable($tablename)) {
  399. self::log("SQL: $tablesql ... ", false);
  400. Vtiger_Utils::ExecuteQuery($tablesql);
  401. self::log("DONE");
  402. }
  403. } else {
  404. if(Vtiger_Utils::IsDestructiveSql($tablesql)) {
  405. self::log("SQL: $tablesql ... SKIPPED");
  406. } else {
  407. self::log("SQL: $tablesql ... ", false);
  408. Vtiger_Utils::ExecuteQuery($tablesql);
  409. self::log("DONE");
  410. }
  411. }
  412. }
  413. if($schemafile) {
  414. fwrite($schemafile, "\t</tables>\n");
  415. fwrite($schemafile, "</schema>\n");
  416. fclose($schemafile);
  417. }
  418. }
  419. /**
  420. * Import Blocks of the module
  421. * @access private
  422. */
  423. function import_Blocks($modulenode, $moduleInstance) {
  424. if(empty($modulenode->blocks) || empty($modulenode->blocks->block)) return;
  425. foreach($modulenode->blocks->block as $blocknode) {
  426. $blockInstance = $this->import_Block($modulenode, $moduleInstance, $blocknode);
  427. $this->import_Fields($blocknode, $blockInstance, $moduleInstance);
  428. }
  429. }
  430. /**
  431. * Import Block of the module
  432. * @access private
  433. */
  434. function import_Block($modulenode, $moduleInstance, $blocknode) {
  435. $blocklabel = $blocknode->label;
  436. $blockInstance = new Vtiger_Block();
  437. $blockInstance->label = $blocklabel;
  438. $moduleInstance->addBlock($blockInstance);
  439. return $blockInstance;
  440. }
  441. /**
  442. * Import Fields of the module
  443. * @access private
  444. */
  445. function import_Fields($blocknode, $blockInstance, $moduleInstance) {
  446. if(empty($blocknode->fields) || empty($blocknode->fields->field)) return;
  447. foreach($blocknode->fields->field as $fieldnode) {
  448. $fieldInstance = $this->import_Field($blocknode, $blockInstance, $moduleInstance, $fieldnode);
  449. }
  450. }
  451. /**
  452. * Import Field of the module
  453. * @access private
  454. */
  455. function import_Field($blocknode, $blockInstance, $moduleInstance, $fieldnode) {
  456. $fieldInstance = new Vtiger_Field();
  457. $fieldInstance->name = $fieldnode->fieldname;
  458. $fieldInstance->label = $fieldnode->fieldlabel;
  459. $fieldInstance->table = $fieldnode->tablename;
  460. $fieldInstance->column = $fieldnode->columnname;
  461. $fieldInstance->uitype = $fieldnode->uitype;
  462. $fieldInstance->generatedtype= $fieldnode->generatedtype;
  463. $fieldInstance->readonly = $fieldnode->readonly;
  464. $fieldInstance->presence = $fieldnode->presence;
  465. $fieldInstance->defaultvalue = $fieldnode->defaultvalue;
  466. $fieldInstance->maximumlength= $fieldnode->maximumlength;
  467. $fieldInstance->sequence = $fieldnode->sequence;
  468. $fieldInstance->quickcreate = $fieldnode->quickcreate;
  469. $fieldInstance->quicksequence= $fieldnode->quickcreatesequence;
  470. $fieldInstance->typeofdata = $fieldnode->typeofdata;
  471. $fieldInstance->displaytype = $fieldnode->displaytype;
  472. $fieldInstance->info_type = $fieldnode->info_type;
  473. if(!empty($fieldnode->helpinfo))
  474. $fieldInstance->helpinfo = $fieldnode->helpinfo;
  475. if(isset($fieldnode->masseditable))
  476. $fieldInstance->masseditable = $fieldnode->masseditable;
  477. if(isset($fieldnode->columntype) && !empty($fieldnode->columntype))
  478. $fieldInstance->columntype = $fieldnode->columntype;
  479. $blockInstance->addField($fieldInstance);
  480. // Set the field as entity identifier if marked.
  481. if(!empty($fieldnode->entityidentifier)) {
  482. $moduleInstance->entityidfield = $fieldnode->entityidentifier->entityidfield;
  483. $moduleInstance->entityidcolumn= $fieldnode->entityidentifier->entityidcolumn;
  484. $moduleInstance->setEntityIdentifier($fieldInstance);
  485. }
  486. // Check picklist values associated with field if any.
  487. if(!empty($fieldnode->picklistvalues) && !empty($fieldnode->picklistvalues->picklistvalue)) {
  488. $picklistvalues = Array();
  489. foreach($fieldnode->picklistvalues->picklistvalue as $picklistvaluenode) {
  490. $picklistvalues[] = $picklistvaluenode;
  491. }
  492. $fieldInstance->setPicklistValues( $picklistvalues );
  493. }
  494. // Check related modules associated with this field
  495. if(!empty($fieldnode->relatedmodules) && !empty($fieldnode->relatedmodules->relatedmodule)) {
  496. $relatedmodules = Array();
  497. foreach($fieldnode->relatedmodules->relatedmodule as $relatedmodulenode) {
  498. $relatedmodules[] = $relatedmodulenode;
  499. }
  500. $fieldInstance->setRelatedModules($relatedmodules);
  501. }
  502. $this->__AddModuleFieldToCache($moduleInstance, $fieldnode->fieldname, $fieldInstance);
  503. return $fieldInstance;
  504. }
  505. /**
  506. * Import Custom views of the module
  507. * @access private
  508. */
  509. function import_CustomViews($modulenode, $moduleInstance) {
  510. if(empty($modulenode->customviews) || empty($modulenode->customviews->customview)) return;
  511. foreach($modulenode->customviews->customview as $customviewnode) {
  512. $filterInstance = $this->import_CustomView($modulenode, $moduleInstance, $customviewnode);
  513. }
  514. }
  515. /**
  516. * Import Custom View of the module
  517. * @access private
  518. */
  519. function import_CustomView($modulenode, $moduleInstance, $customviewnode) {
  520. $viewname = $customviewnode->viewname;
  521. $setdefault=$customviewnode->setdefault;
  522. $setmetrics=$customviewnode->setmetrics;
  523. $filterInstance = new Vtiger_Filter();
  524. $filterInstance->name = $viewname;
  525. $filterInstance->isdefault = $setdefault;
  526. $filterInstance->inmetrics = $setmetrics;
  527. $moduleInstance->addFilter($filterInstance);
  528. foreach($customviewnode->fields->field as $fieldnode) {
  529. $fieldInstance = $this->__GetModuleFieldFromCache($moduleInstance, $fieldnode->fieldname);
  530. $filterInstance->addField($fieldInstance, $fieldnode->columnindex);
  531. if(!empty($fieldnode->rules->rule)) {
  532. foreach($fieldnode->rules->rule as $rulenode) {
  533. $filterInstance->addRule($fieldInstance, $rulenode->comparator, $rulenode->value, $rulenode->columnindex);
  534. }
  535. }
  536. }
  537. }
  538. /**
  539. * Import Sharing Access of the module
  540. * @access private
  541. */
  542. function import_SharingAccess($modulenode, $moduleInstance) {
  543. if(empty($modulenode->sharingaccess)) return;
  544. if(!empty($modulenode->sharingaccess->default)) {
  545. foreach($modulenode->sharingaccess->default as $defaultnode) {
  546. $moduleInstance->setDefaultSharing($defaultnode);
  547. }
  548. }
  549. }
  550. /**
  551. * Import Events of the module
  552. * @access private
  553. */
  554. function import_Events($modulenode, $moduleInstance) {
  555. if(empty($modulenode->events) || empty($modulenode->events->event)) return;
  556. if(Vtiger_Event::hasSupport()) {
  557. foreach($modulenode->events->event as $eventnode) {
  558. $this->import_Event($modulenode, $moduleInstance, $eventnode);
  559. }
  560. }
  561. }
  562. /**
  563. * Import Event of the module
  564. * @access private
  565. */
  566. function import_Event($modulenode, $moduleInstance, $eventnode) {
  567. $event_condition = '';
  568. $event_dependent = '[]';
  569. if(!empty($eventnode->condition)) $event_condition = "$eventnode->condition";
  570. if(!empty($eventnode->dependent)) $event_dependent = "$eventnode->dependent";
  571. Vtiger_Event::register($moduleInstance,
  572. (string)$eventnode->eventname, (string)$eventnode->classname,
  573. (string)$eventnode->filename, (string)$event_condition, (string)$event_dependent
  574. );
  575. }
  576. /**
  577. * Import actions of the module
  578. * @access private
  579. */
  580. function import_Actions($modulenode, $moduleInstance) {
  581. if(empty($modulenode->actions) || empty($modulenode->actions->action)) return;
  582. foreach($modulenode->actions->action as $actionnode) {
  583. $this->import_Action($modulenode, $moduleInstance, $actionnode);
  584. }
  585. }
  586. /**
  587. * Import action of the module
  588. * @access private
  589. */
  590. function import_Action($modulenode, $moduleInstance, $actionnode) {
  591. $actionstatus = $actionnode->status;
  592. if($actionstatus == 'enabled')
  593. $moduleInstance->enableTools($actionnode->name);
  594. else
  595. $moduleInstance->disableTools($actionnode->name);
  596. }
  597. /**
  598. * Import related lists of the module
  599. * @access private
  600. */
  601. function import_RelatedLists($modulenode, $moduleInstance) {
  602. if(empty($modulenode->relatedlists) || empty($modulenode->relatedlists->relatedlist)) return;
  603. foreach($modulenode->relatedlists->relatedlist as $relatedlistnode) {
  604. $relModuleInstance = $this->import_Relatedlist($modulenode, $moduleInstance, $relatedlistnode);
  605. }
  606. }
  607. /**
  608. * Import related list of the module.
  609. * @access private
  610. */
  611. function import_Relatedlist($modulenode, $moduleInstance, $relatedlistnode) {
  612. $relModuleInstance = Vtiger_Module::getInstance($relatedlistnode->relatedmodule);
  613. $label = $relatedlistnode->label;
  614. $actions = false;
  615. if(!empty($relatedlistnode->actions) && !empty($relatedlistnode->actions->action)) {
  616. $actions = Array();
  617. foreach($relatedlistnode->actions->action as $actionnode) {
  618. $actions[] = "$actionnode";
  619. }
  620. }
  621. if($relModuleInstance) {
  622. $moduleInstance->setRelatedList($relModuleInstance, "$label", $actions, "$relatedlistnode->function");
  623. }
  624. return $relModuleInstance;
  625. }
  626. /**
  627. * Import custom links of the module.
  628. * @access private
  629. */
  630. function import_CustomLinks($modulenode, $moduleInstance) {
  631. if(empty($modulenode->customlinks) || empty($modulenode->customlinks->customlink)) return;
  632. foreach($modulenode->customlinks->customlink as $customlinknode) {
  633. $handlerInfo = null;
  634. if(!empty($customlinknode->handler_path)) {
  635. $handlerInfo = array();
  636. $handlerInfo = array("$customlinknode->handler_path",
  637. "$customlinknode->handler_class",
  638. "$customlinknode->handler");
  639. }
  640. $moduleInstance->addLink(
  641. "$customlinknode->linktype",
  642. "$customlinknode->linklabel",
  643. "$customlinknode->linkurl",
  644. "$customlinknode->linkicon",
  645. "$customlinknode->sequence",
  646. $handlerInfo
  647. );
  648. }
  649. }
  650. /**
  651. * Import cron jobs of the module.
  652. * @access private
  653. */
  654. function import_CronTasks($modulenode){
  655. if(empty($modulenode->crons) || empty($modulenode->crons->cron)) return;
  656. foreach ($modulenode->crons->cron as $cronTask){
  657. if(empty($cronTask->status)){
  658. $cronTask->status=Vtiger_Cron::$STATUS_ENABLED;
  659. }
  660. if((empty($cronTask->sequence))){
  661. $cronTask->sequence=Vtiger_Cron::nextSequence();
  662. }
  663. Vtiger_Cron::register("$cronTask->name","$cronTask->handler", "$cronTask->frequency", "$modulenode->name","$cronTask->status","$cronTask->sequence","$cronTask->description");
  664. }
  665. }
  666. }
  667. ?>