$extensionId * @return */ public function setId($extensionId) { $this->set('id', $extensionId); return $this; } /** * Function to set file name for this instance * @param $fileName * @return */ public function setFileName($fileName) { $this->fileName = $fileName; return $this; } /** * Function to get Id of this instance * @return id */ public function getId() { return $this->get('id'); } /** * Function to get name of this instance * @return module name */ public function getName() { return $this->get('name'); } /** * Function to get file name of this instance * @return file name */ public function getFileName() { return $this->fileName; } /** * Function to get package of this instance * @return package object */ public function getPackage() { $packageModel = new Vtiger_Package(); $moduleName = $packageModel->getModuleNameFromZip(self::getUploadDirectory(). '/' .$this->getFileName()); if ($moduleName) { return $packageModel; } return false; } /** * Function to check whether it is compatible with vtiger or not * @return true/false */ public function isVtigerCompatible() { vimport('~~/vtlib/Vtiger/Version.php'); $vtigerVersion = $this->get('vtigerVersion'); $vtigerMaxVersion = $this->get('vtigerMaxVersion'); if ((Vtiger_Version::check($vtigerVersion, '>=') && $vtigerMaxVersion && Vtiger_Version::check($vtigerMaxVersion, '<')) || Vtiger_Version::check($vtigerVersion, '=')) { return true; } return false; } /** * Function to check whether the module is already exists or not * @return */ public function isAlreadyExists() { $moduleName = $this->getName(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); if($moduleModel) { return true; } return false; } /** * Function to check whether the module is upgradable or not * @return */ public function isUpgradable() { $moduleName = $this->getName(); $moduleModel = Vtiger_Module_Model::getInstance($moduleName); if ($moduleModel) { if ($moduleModel->get('version') < $this->get('pkgVersion')) { return true; } } return false; } /** * Function to get instance by using XML node * @param $extensionXMLNode * @return $extensionModel */ public static function getInstanceFromXMLNodeObject($extensionXMLNode) { $extensionModel = new self(); $objectProperties = get_object_vars($extensionXMLNode); foreach($objectProperties as $propertyName => $propertyValue) { $propertyValue = (string)$propertyValue; if ($propertyName === 'description') { $propertyValue = nl2br(str_replace(array('<','>'), array('<', '>'), br2nl(trim($propertyValue)))); } $extensionModel->set($propertyName, $propertyValue); } $label = $extensionModel->get('label'); if (!$label) { $extensionModel->set('label', $extensionModel->getName()); } return $extensionModel; } /** * Function to get instance by using id * @param $extensionId * @param $fileName * @return $extension Model */ public static function getInstanceById($extensionId, $fileName = false) { $uploadDir = self::getUploadDirectory(); if ($fileName) { if (is_dir($uploadDir)) { $uploadFileName = "$uploadDir/$fileName"; checkFileAccess(self::getUploadDirectory()); $extensionModel = new self(); $extensionModel->setId($extensionId)->setFileName($fileName); return $extensionModel; } } else { if (!is_dir($uploadDir)) { mkdir($uploadDir); } $uploadFile = 'usermodule_'. time() . '.zip'; $uploadFileName = "$uploadDir/$uploadFile"; checkFileAccess(self::getUploadDirectory()); $packageAvailable = Settings_ModuleManager_Extension_Model::download($extensionId, $uploadFileName); if ($packageAvailable) { $extensionModel = new self(); $extensionModel->setId($extensionId)->setFileName($uploadFile); return $extensionModel; } } return false; } /** * Function to download the file of this instance * @param $extensionId * @param $targetFileName * @return true/false */ public static function download($extensionId, $targetFileName) { $extensions = self::getAll(); $downloadURL = $extensions[$extensionId]->get('downloadURL'); if ($downloadURL) { $clientModel = new Vtiger_Net_Client($downloadURL); file_put_contents($targetFileName, $clientModel->doGet()); return true; } return false; } }