BxDolStudioInstallerQuery.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentStudio Trident Studio
  7. * @{
  8. */
  9. bx_import('BxDolModuleQuery');
  10. class BxDolStudioInstallerQuery extends BxDolModuleQuery
  11. {
  12. function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. function getRelationsBy($aParams = array())
  17. {
  18. $sMethod = 'getAll';
  19. $sWhereClause = "";
  20. switch($aParams['type']) {
  21. case 'module':
  22. $sMethod = 'getRow';
  23. $sWhereClause .= $this->prepare(" AND `module`=?", $aParams['value']);
  24. break;
  25. }
  26. $sSql = "SELECT
  27. `id`,
  28. `module`,
  29. `on_install`,
  30. `on_uninstall`,
  31. `on_enable`,
  32. `on_disable`
  33. FROM `sys_modules_relations`
  34. WHERE 1" . $sWhereClause;
  35. return $this->$sMethod($sSql);
  36. }
  37. function insertModule(&$aConfig)
  38. {
  39. $sHelpUrl = isset($aConfig['help_url']) ? $aConfig['help_url'] : '';
  40. $sDependencies = '';
  41. if(isset($aConfig['dependencies']) && is_array($aConfig['dependencies']))
  42. $sDependencies = implode(',', $aConfig['dependencies']);
  43. $sQuery = $this->prepare("INSERT IGNORE INTO `sys_modules`(`type`, `name`, `title`, `vendor`, `version`, `help_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `dependencies`, `date`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UNIX_TIMESTAMP())", $aConfig['type'], $aConfig['name'], $aConfig['title'], $aConfig['vendor'], $aConfig['version'], $sHelpUrl, $aConfig['home_dir'], $aConfig['home_uri'], $aConfig['class_prefix'], $aConfig['db_prefix'], $aConfig['language_category'], $sDependencies);
  44. $iResult = (int)$this->query($sQuery);
  45. return $iResult > 0 ? (int)$this->lastId() : 0;
  46. }
  47. function insertModuleTrack($iModuleId, &$aFile)
  48. {
  49. $sQuery = $this->prepare("INSERT IGNORE INTO `sys_modules_file_tracks`(`module_id`, `file`, `hash`) VALUES(?, ?, ?)", $iModuleId, $aFile['file'], $aFile['hash']);
  50. $this->query($sQuery);
  51. }
  52. function getModuleTrackFiles($iModuleId)
  53. {
  54. $sQuery = $this->prepare("SELECT `file`, `hash` FROM `sys_modules_file_tracks` WHERE `module_id` = ?", $iModuleId);
  55. return $this->getAllWithKey($sQuery, "file");
  56. }
  57. function deleteModuleTrackFiles($iModuleId)
  58. {
  59. $sQuery = $this->prepare("DELETE FROM `sys_modules_file_tracks` WHERE `module_id` = ?", $iModuleId);
  60. return $this->query($sQuery);
  61. }
  62. function deleteModule($aConfig)
  63. {
  64. $sQuery = $this->prepare("SELECT `id` FROM `sys_modules` WHERE `vendor`=? AND `path`=? LIMIT 1", $aConfig['vendor'], $aConfig['home_dir']);
  65. $iId = (int)$this->getOne($sQuery);
  66. $sQuery = $this->prepare("DELETE FROM `sys_modules` WHERE `vendor`=? AND `path`=? LIMIT 1", $aConfig['vendor'], $aConfig['home_dir']);
  67. $this->query($sQuery);
  68. $this->deleteModuleTrackFiles($iId);
  69. return $iId;
  70. }
  71. }
  72. /** @} */