PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/vtlib/Vtiger/PackageImport.php

https://bitbucket.org/thomashii/vtigercrm-5.4-for-postgresql
PHP | 739 lines | 460 code | 88 blank | 191 comment | 98 complexity | 043b60f70d2cf9bee07ee5580d8bdd73 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.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. // Check for language file.
  158. preg_match("/modules\/([^\/]+)\/language\/en_us.lang.php/", $filename, $matches);
  159. if(count($matches)) { $language_modulename = $matches[1]; continue; }
  160. }
  161. // Verify module language file.
  162. if(!empty($language_modulename) && $language_modulename == $modulename) {
  163. $languagefile_found = true;
  164. }
  165. if(!empty($this->_modulexml) &&
  166. !empty($this->_modulexml->dependencies) &&
  167. !empty($this->_modulexml->dependencies->vtiger_version)) {
  168. $vtigerversion_found = true;
  169. }
  170. $validzip = false;
  171. if($manifestxml_found && $languagefile_found && $vtigerversion_found)
  172. $validzip = true;
  173. if($validzip) {
  174. if(!empty($this->_modulexml->license)) {
  175. if(!empty($this->_modulexml->license->inline)) {
  176. $this->_licensetext = $this->_modulexml->license->inline;
  177. } else if(!empty($this->_modulexml->license->file)) {
  178. $licensefile = $this->_modulexml->license->file;
  179. $licensefile = "$licensefile";
  180. if(!empty($filelist[$licensefile])) {
  181. $this->_licensetext = $unzip->unzip($licensefile);
  182. } else {
  183. $this->_licensetext = "Missing $licensefile!";
  184. }
  185. }
  186. }
  187. }
  188. if($unzip) $unzip->close();
  189. return $validzip;
  190. }
  191. /**
  192. * Get module name packaged in the zip file
  193. * @access private
  194. */
  195. function getModuleNameFromZip($zipfile) {
  196. if(!$this->checkZip($zipfile)) return null;
  197. return (string)$this->_modulexml->name;
  198. }
  199. /**
  200. * returns the name of the module.
  201. * @return String - name of the module as given in manifest file.
  202. */
  203. function getModuleName() {
  204. return (string)$this->_modulexml->name;
  205. }
  206. /**
  207. * Cache the field instance for re-use
  208. * @access private
  209. */
  210. function __AddModuleFieldToCache($moduleInstance, $fieldname, $fieldInstance) {
  211. $this->_modulefields_cache["$moduleInstance->name"]["$fieldname"] = $fieldInstance;
  212. }
  213. /**
  214. * Get field instance from cache
  215. * @access private
  216. */
  217. function __GetModuleFieldFromCache($moduleInstance, $fieldname) {
  218. return $this->_modulefields_cache["$moduleInstance->name"]["$fieldname"];
  219. }
  220. /**
  221. * Initialize Import
  222. * @access private
  223. */
  224. function initImport($zipfile, $overwrite) {
  225. $module = $this->getModuleNameFromZip($zipfile);
  226. if($module != null) {
  227. $unzip = new Vtiger_Unzip($zipfile, $overwrite);
  228. // Unzip selectively
  229. $unzip->unzipAllEx( ".",
  230. Array(
  231. // Include only file/folders that need to be extracted
  232. 'include' => Array('templates', "modules/$module", 'cron'),
  233. //'exclude' => Array('manifest.xml')
  234. // NOTE: If excludes is not given then by those not mentioned in include are ignored.
  235. ),
  236. // What files needs to be renamed?
  237. Array(
  238. // Templates folder
  239. 'templates' => "Smarty/templates/modules/$module",
  240. // Cron folder
  241. 'cron' => "cron/modules/$module"
  242. )
  243. );
  244. if($unzip) $unzip->close();
  245. }
  246. return $module;
  247. }
  248. function getTemporaryFilePath($filepath=false) {
  249. return 'cache/'. $filepath;
  250. }
  251. /**
  252. * Get dependent version
  253. * @access private
  254. */
  255. function getDependentVtigerVersion() {
  256. return $this->_modulexml->dependencies->vtiger_version;
  257. }
  258. /**
  259. * Get dependent Maximum version
  260. * @access private
  261. */
  262. function getDependentMaxVtigerVersion() {
  263. return $this->_modulexml->dependencies->vtiger_max_version;
  264. }
  265. /**
  266. * Get package version
  267. * @access private
  268. */
  269. function getVersion() {
  270. return $this->_modulexml->version;
  271. }
  272. /**
  273. * Import Module from zip file
  274. * @param String Zip file name
  275. * @param Boolean True for overwriting existing module
  276. *
  277. * @todo overwrite feature is not functionally currently.
  278. */
  279. function import($zipfile, $overwrite=false) {
  280. $module = $this->getModuleNameFromZip($zipfile);
  281. if($module != null) {
  282. // If data is not yet available
  283. if(empty($this->_modulexml)) {
  284. $this->__parseManifestFile($unzip);
  285. }
  286. $buildModuleArray = array();
  287. $installSequenceArray = array();
  288. $moduleBundle = (boolean)$this->_modulexml->modulebundle;
  289. if($moduleBundle == true) {
  290. $moduleList = (Array)$this->_modulexml->modulelist;
  291. foreach($moduleList as $moduleInfos) {
  292. foreach($moduleInfos as $moduleInfo) {
  293. $moduleInfo = (Array)$moduleInfo;
  294. $buildModuleArray[] = $moduleInfo;
  295. $installSequenceArray[] = $moduleInfo['install_sequence'];
  296. }
  297. }
  298. sort($installSequenceArray);
  299. $unzip = new Vtiger_Unzip($zipfile);
  300. $unzip->unzipAllEx($this->getTemporaryFilePath());
  301. foreach ($installSequenceArray as $sequence) {
  302. foreach ($buildModuleArray as $moduleInfo) {
  303. if($moduleInfo['install_sequence'] == $sequence) {
  304. $this->import($this->getTemporaryFilePath($moduleInfo['filepath']), $overwrite);
  305. }
  306. }
  307. }
  308. } else {
  309. $module = $this->initImport($zipfile, $overwrite);
  310. // Call module import function
  311. $this->import_Module();
  312. }
  313. }
  314. }
  315. /**
  316. * Import Module
  317. * @access private
  318. */
  319. function import_Module() {
  320. $tabname = $this->_modulexml->name;
  321. $tablabel= $this->_modulexml->label;
  322. $parenttab=(string)$this->_modulexml->parent;
  323. $tabversion=$this->_modulexml->version;
  324. $isextension= false;
  325. if(!empty($this->_modulexml->type)) {
  326. $type = strtolower($this->_modulexml->type);
  327. if($type == 'extension' || $type == 'language')
  328. $isextension = true;
  329. }
  330. $vtigerMinVersion = $this->_modulexml->dependencies->vtiger_version;
  331. $vtigerMaxVersion = $this->_modulexml->dependencies->vtiger_max_version;
  332. $moduleInstance = new Vtiger_Module();
  333. $moduleInstance->name = $tabname;
  334. $moduleInstance->label= $tablabel;
  335. $moduleInstance->parent=$parenttab;
  336. $moduleInstance->isentitytype = ($isextension != true);
  337. $moduleInstance->version = (!$tabversion)? 0 : $tabversion;
  338. $moduleInstance->minversion = (!$vtigerMinVersion)? false : $vtigerMinVersion;
  339. $moduleInstance->maxversion = (!$vtigerMaxVersion)? false : $vtigerMaxVersion;
  340. $moduleInstance->save();
  341. if(!empty($parenttab)) {
  342. $menuInstance = Vtiger_Menu::getInstance($parenttab);
  343. $menuInstance->addModule($moduleInstance);
  344. }
  345. $this->import_Tables($this->_modulexml);
  346. $this->import_Blocks($this->_modulexml, $moduleInstance);
  347. $this->import_CustomViews($this->_modulexml, $moduleInstance);
  348. $this->import_SharingAccess($this->_modulexml, $moduleInstance);
  349. $this->import_Events($this->_modulexml, $moduleInstance);
  350. $this->import_Actions($this->_modulexml, $moduleInstance);
  351. $this->import_RelatedLists($this->_modulexml, $moduleInstance);
  352. $this->import_CustomLinks($this->_modulexml, $moduleInstance);
  353. $this->import_CronTasks($this->_modulexml);
  354. Vtiger_Module::fireEvent($moduleInstance->name,
  355. Vtiger_Module::EVENT_MODULE_POSTINSTALL);
  356. $moduleInstance->initWebservice();
  357. }
  358. /**
  359. * Import Tables of the module
  360. * @access private
  361. */
  362. function import_Tables($modulenode) {
  363. if(empty($modulenode->tables) || empty($modulenode->tables->table)) return;
  364. /**
  365. * Record the changes in schema file
  366. */
  367. $schemafile = fopen("modules/$modulenode->name/schema.xml", 'w');
  368. if($schemafile) {
  369. fwrite($schemafile, "<?xml version='1.0'?>\n");
  370. fwrite($schemafile, "<schema>\n");
  371. fwrite($schemafile, "\t<tables>\n");
  372. }
  373. // Import the table via queries
  374. foreach($modulenode->tables->table as $tablenode) {
  375. $tablename = $tablenode->name;
  376. $tablesql = "$tablenode->sql"; // Convert to string format
  377. // Save the information in the schema file.
  378. fwrite($schemafile, "\t\t<table>\n");
  379. fwrite($schemafile, "\t\t\t<name>$tablename</name>\n");
  380. fwrite($schemafile, "\t\t\t<sql><![CDATA[$tablesql]]></sql>\n");
  381. fwrite($schemafile, "\t\t</table>\n");
  382. // Avoid executing SQL that will DELETE or DROP table data
  383. if(Vtiger_Utils::IsCreateSql($tablesql)) {
  384. if(!Vtiger_Utils::checkTable($tablename)) {
  385. self::log("SQL: $tablesql ... ", false);
  386. Vtiger_Utils::ExecuteQuery($tablesql);
  387. self::log("DONE");
  388. }
  389. } else {
  390. if(Vtiger_Utils::IsDestructiveSql($tablesql)) {
  391. self::log("SQL: $tablesql ... SKIPPED");
  392. } else {
  393. self::log("SQL: $tablesql ... ", false);
  394. Vtiger_Utils::ExecuteQuery($tablesql);
  395. self::log("DONE");
  396. }
  397. }
  398. }
  399. if($schemafile) {
  400. fwrite($schemafile, "\t</tables>\n");
  401. fwrite($schemafile, "</schema>\n");
  402. fclose($schemafile);
  403. }
  404. }
  405. /**
  406. * Import Blocks of the module
  407. * @access private
  408. */
  409. function import_Blocks($modulenode, $moduleInstance) {
  410. if(empty($modulenode->blocks) || empty($modulenode->blocks->block)) return;
  411. foreach($modulenode->blocks->block as $blocknode) {
  412. $blockInstance = $this->import_Block($modulenode, $moduleInstance, $blocknode);
  413. $this->import_Fields($blocknode, $blockInstance, $moduleInstance);
  414. }
  415. }
  416. /**
  417. * Import Block of the module
  418. * @access private
  419. */
  420. function import_Block($modulenode, $moduleInstance, $blocknode) {
  421. $blocklabel = $blocknode->label;
  422. $blockInstance = new Vtiger_Block();
  423. $blockInstance->label = $blocklabel;
  424. $moduleInstance->addBlock($blockInstance);
  425. return $blockInstance;
  426. }
  427. /**
  428. * Import Fields of the module
  429. * @access private
  430. */
  431. function import_Fields($blocknode, $blockInstance, $moduleInstance) {
  432. if(empty($blocknode->fields) || empty($blocknode->fields->field)) return;
  433. foreach($blocknode->fields->field as $fieldnode) {
  434. $fieldInstance = $this->import_Field($blocknode, $blockInstance, $moduleInstance, $fieldnode);
  435. }
  436. }
  437. /**
  438. * Import Field of the module
  439. * @access private
  440. */
  441. function import_Field($blocknode, $blockInstance, $moduleInstance, $fieldnode) {
  442. $fieldInstance = new Vtiger_Field();
  443. $fieldInstance->name = $fieldnode->fieldname;
  444. $fieldInstance->label = $fieldnode->fieldlabel;
  445. $fieldInstance->table = $fieldnode->tablename;
  446. $fieldInstance->column = $fieldnode->columnname;
  447. $fieldInstance->uitype = $fieldnode->uitype;
  448. $fieldInstance->generatedtype= $fieldnode->generatedtype;
  449. $fieldInstance->readonly = $fieldnode->readonly;
  450. $fieldInstance->presence = $fieldnode->presence;
  451. $fieldInstance->defaultvalue = $fieldnode->defaultvalue;
  452. $fieldInstance->maximumlength= $fieldnode->maximumlength;
  453. $fieldInstance->sequence = $fieldnode->sequence;
  454. $fieldInstance->quickcreate = $fieldnode->quickcreate;
  455. $fieldInstance->quicksequence= $fieldnode->quickcreatesequence;
  456. $fieldInstance->typeofdata = $fieldnode->typeofdata;
  457. $fieldInstance->displaytype = $fieldnode->displaytype;
  458. $fieldInstance->info_type = $fieldnode->info_type;
  459. if(!empty($fieldnode->helpinfo))
  460. $fieldInstance->helpinfo = $fieldnode->helpinfo;
  461. if(isset($fieldnode->masseditable))
  462. $fieldInstance->masseditable = $fieldnode->masseditable;
  463. if(isset($fieldnode->columntype) && !empty($fieldnode->columntype))
  464. $fieldInstance->columntype = $fieldnode->columntype;
  465. $blockInstance->addField($fieldInstance);
  466. // Set the field as entity identifier if marked.
  467. if(!empty($fieldnode->entityidentifier)) {
  468. $moduleInstance->entityidfield = $fieldnode->entityidentifier->entityidfield;
  469. $moduleInstance->entityidcolumn= $fieldnode->entityidentifier->entityidcolumn;
  470. $moduleInstance->setEntityIdentifier($fieldInstance);
  471. }
  472. // Check picklist values associated with field if any.
  473. if(!empty($fieldnode->picklistvalues) && !empty($fieldnode->picklistvalues->picklistvalue)) {
  474. $picklistvalues = Array();
  475. foreach($fieldnode->picklistvalues->picklistvalue as $picklistvaluenode) {
  476. $picklistvalues[] = $picklistvaluenode;
  477. }
  478. $fieldInstance->setPicklistValues( $picklistvalues );
  479. }
  480. // Check related modules associated with this field
  481. if(!empty($fieldnode->relatedmodules) && !empty($fieldnode->relatedmodules->relatedmodule)) {
  482. $relatedmodules = Array();
  483. foreach($fieldnode->relatedmodules->relatedmodule as $relatedmodulenode) {
  484. $relatedmodules[] = $relatedmodulenode;
  485. }
  486. $fieldInstance->setRelatedModules($relatedmodules);
  487. }
  488. $this->__AddModuleFieldToCache($moduleInstance, $fieldnode->fieldname, $fieldInstance);
  489. return $fieldInstance;
  490. }
  491. /**
  492. * Import Custom views of the module
  493. * @access private
  494. */
  495. function import_CustomViews($modulenode, $moduleInstance) {
  496. if(empty($modulenode->customviews) || empty($modulenode->customviews->customview)) return;
  497. foreach($modulenode->customviews->customview as $customviewnode) {
  498. $filterInstance = $this->import_CustomView($modulenode, $moduleInstance, $customviewnode);
  499. }
  500. }
  501. /**
  502. * Import Custom View of the module
  503. * @access private
  504. */
  505. function import_CustomView($modulenode, $moduleInstance, $customviewnode) {
  506. $viewname = $customviewnode->viewname;
  507. $setdefault=$customviewnode->setdefault;
  508. $setmetrics=$customviewnode->setmetrics;
  509. $filterInstance = new Vtiger_Filter();
  510. $filterInstance->name = $viewname;
  511. $filterInstance->isdefault = $setdefault;
  512. $filterInstance->inmetrics = $setmetrics;
  513. $moduleInstance->addFilter($filterInstance);
  514. foreach($customviewnode->fields->field as $fieldnode) {
  515. $fieldInstance = $this->__GetModuleFieldFromCache($moduleInstance, $fieldnode->fieldname);
  516. $filterInstance->addField($fieldInstance, $fieldnode->columnindex);
  517. if(!empty($fieldnode->rules->rule)) {
  518. foreach($fieldnode->rules->rule as $rulenode) {
  519. $filterInstance->addRule($fieldInstance, $rulenode->comparator, $rulenode->value, $rulenode->columnindex);
  520. }
  521. }
  522. }
  523. }
  524. /**
  525. * Import Sharing Access of the module
  526. * @access private
  527. */
  528. function import_SharingAccess($modulenode, $moduleInstance) {
  529. if(empty($modulenode->sharingaccess)) return;
  530. if(!empty($modulenode->sharingaccess->default)) {
  531. foreach($modulenode->sharingaccess->default as $defaultnode) {
  532. $moduleInstance->setDefaultSharing($defaultnode);
  533. }
  534. }
  535. }
  536. /**
  537. * Import Events of the module
  538. * @access private
  539. */
  540. function import_Events($modulenode, $moduleInstance) {
  541. if(empty($modulenode->events) || empty($modulenode->events->event)) return;
  542. if(Vtiger_Event::hasSupport()) {
  543. foreach($modulenode->events->event as $eventnode) {
  544. $this->import_Event($modulenode, $moduleInstance, $eventnode);
  545. }
  546. }
  547. }
  548. /**
  549. * Import Event of the module
  550. * @access private
  551. */
  552. function import_Event($modulenode, $moduleInstance, $eventnode) {
  553. $event_condition = '';
  554. if(!empty($eventnode->condition)) $event_condition = "$eventnode->condition";
  555. Vtiger_Event::register($moduleInstance,
  556. (string)$eventnode->eventname, (string)$eventnode->classname,
  557. (string)$eventnode->filename, (string)$event_condition
  558. );
  559. }
  560. /**
  561. * Import actions of the module
  562. * @access private
  563. */
  564. function import_Actions($modulenode, $moduleInstance) {
  565. if(empty($modulenode->actions) || empty($modulenode->actions->action)) return;
  566. foreach($modulenode->actions->action as $actionnode) {
  567. $this->import_Action($modulenode, $moduleInstance, $actionnode);
  568. }
  569. }
  570. /**
  571. * Import action of the module
  572. * @access private
  573. */
  574. function import_Action($modulenode, $moduleInstance, $actionnode) {
  575. $actionstatus = $actionnode->status;
  576. if($actionstatus == 'enabled')
  577. $moduleInstance->enableTools($actionnode->name);
  578. else
  579. $moduleInstance->disableTools($actionnode->name);
  580. }
  581. /**
  582. * Import related lists of the module
  583. * @access private
  584. */
  585. function import_RelatedLists($modulenode, $moduleInstance) {
  586. if(empty($modulenode->relatedlists) || empty($modulenode->relatedlists->relatedlist)) return;
  587. foreach($modulenode->relatedlists->relatedlist as $relatedlistnode) {
  588. $relModuleInstance = $this->import_Relatedlist($modulenode, $moduleInstance, $relatedlistnode);
  589. }
  590. }
  591. /**
  592. * Import related list of the module.
  593. * @access private
  594. */
  595. function import_Relatedlist($modulenode, $moduleInstance, $relatedlistnode) {
  596. $relModuleInstance = Vtiger_Module::getInstance($relatedlistnode->relatedmodule);
  597. $label = $relatedlistnode->label;
  598. $actions = false;
  599. if(!empty($relatedlistnode->actions) && !empty($relatedlistnode->actions->action)) {
  600. $actions = Array();
  601. foreach($relatedlistnode->actions->action as $actionnode) {
  602. $actions[] = "$actionnode";
  603. }
  604. }
  605. if($relModuleInstance) {
  606. $moduleInstance->setRelatedList($relModuleInstance, "$label", $actions, "$relatedlistnode->function");
  607. }
  608. return $relModuleInstance;
  609. }
  610. /**
  611. * Import custom links of the module.
  612. * @access private
  613. */
  614. function import_CustomLinks($modulenode, $moduleInstance) {
  615. if(empty($modulenode->customlinks) || empty($modulenode->customlinks->customlink)) return;
  616. foreach($modulenode->customlinks->customlink as $customlinknode) {
  617. $handlerInfo = null;
  618. if(!empty($customlinknode->handler_path)) {
  619. $handlerInfo = array();
  620. $handlerInfo = array("$customlinknode->handler_path",
  621. "$customlinknode->handler_class",
  622. "$customlinknode->handler");
  623. }
  624. $moduleInstance->addLink(
  625. "$customlinknode->linktype",
  626. "$customlinknode->linklabel",
  627. "$customlinknode->linkurl",
  628. "$customlinknode->linkicon",
  629. "$customlinknode->sequence",
  630. $handlerInfo
  631. );
  632. }
  633. }
  634. /**
  635. * Import cron jobs of the module.
  636. * @access private
  637. */
  638. function import_CronTasks($modulenode){
  639. if(empty($modulenode->crons) || empty($modulenode->crons->cron)) return;
  640. foreach ($modulenode->crons->cron as $cronTask){
  641. if(empty($cronTask->status)){
  642. $cronTask->status=Vtiger_Cron::$STATUS_ENABLED;
  643. }
  644. if((empty($cronTask->sequence))){
  645. $cronTask->sequence=Vtiger_Cron::nextSequence();
  646. }
  647. Vtiger_Cron::register("$cronTask->name","$cronTask->handler", "$cronTask->frequency", "$modulenode->name","$cronTask->status","$cronTask->sequence","$cronTask->description");
  648. }
  649. }
  650. }
  651. ?>