BxDolStudioInstallerQuery.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaStudio UNA Studio
  7. * @{
  8. */
  9. class BxDolStudioInstallerQuery extends BxDolModuleQuery
  10. {
  11. function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. function insertRelation($sModule, $aRelation)
  16. {
  17. $aRelation['module'] = $sModule;
  18. return (int)$this->query("INSERT INTO `sys_modules_relations` SET `module`=:module, `on_install`=:on_install, `on_uninstall`=:on_uninstall, `on_enable`=:on_enable, `on_disable`=:on_disable", $aRelation) > 0;
  19. }
  20. function deleteRelation($sModule)
  21. {
  22. $sQuery = $this->prepare("DELETE FROM `sys_modules_relations` WHERE `module`=? LIMIT 1", $sModule);
  23. return (int)$this->query($sQuery) > 0;
  24. }
  25. function getRelationsBy($aParams = array())
  26. {
  27. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  28. $sWhereClause = "";
  29. switch($aParams['type']) {
  30. case 'module':
  31. $aMethod['name'] = 'getRow';
  32. $aMethod['params'][1] = array(
  33. 'module' => $aParams['value']
  34. );
  35. $sWhereClause .= " AND `module`=:module";
  36. break;
  37. }
  38. $aMethod['params'][0] = "SELECT
  39. `id`,
  40. `module`,
  41. `on_install`,
  42. `on_uninstall`,
  43. `on_enable`,
  44. `on_disable`
  45. FROM `sys_modules_relations`
  46. WHERE 1" . $sWhereClause;
  47. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  48. }
  49. function insertModule(&$aConfig)
  50. {
  51. $sHelpUrl = isset($aConfig['help_url']) ? $aConfig['help_url'] : '';
  52. $sNote = isset($aConfig['note']) ? $aConfig['note'] : '';
  53. $sDependencies = '';
  54. if(isset($aConfig['install']['check_dependencies']) && (int)$aConfig['install']['check_dependencies'] == 1 && !empty($aConfig['dependencies']) && is_array($aConfig['dependencies']))
  55. $sDependencies = implode(',', array_keys($aConfig['dependencies']));
  56. $sQuery = $this->prepare("INSERT IGNORE INTO `sys_modules`(`type`, `name`, `title`, `note`, `vendor`, `version`, `help_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `dependencies`, `date`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UNIX_TIMESTAMP())", $aConfig['type'], $aConfig['name'], $aConfig['title'], $sNote, $aConfig['vendor'], $aConfig['version'], $sHelpUrl, $aConfig['home_dir'], $aConfig['home_uri'], $aConfig['class_prefix'], $aConfig['db_prefix'], $aConfig['language_category'], $sDependencies);
  57. $iResult = (int)$this->query($sQuery);
  58. if ($iResult > 0) {
  59. $iRet = (int)$this->lastId();
  60. $this->cleanCache('sys_modules_list');
  61. return $iRet;
  62. } else {
  63. return 0;
  64. }
  65. }
  66. function insertModuleTrack($iModuleId, &$aFile)
  67. {
  68. $sQuery = $this->prepare("INSERT IGNORE INTO `sys_modules_file_tracks`(`module_id`, `file`, `hash`) VALUES(?, ?, ?)", $iModuleId, $aFile['file'], $aFile['hash']);
  69. $this->query($sQuery);
  70. }
  71. function getModuleTrackFiles($iModuleId)
  72. {
  73. $sQuery = $this->prepare("SELECT `file`, `hash` FROM `sys_modules_file_tracks` WHERE `module_id` = ?", $iModuleId);
  74. return $this->getAllWithKey($sQuery, "file");
  75. }
  76. function deleteModuleTrackFiles($iModuleId)
  77. {
  78. $sQuery = $this->prepare("DELETE FROM `sys_modules_file_tracks` WHERE `module_id` = ?", $iModuleId);
  79. return $this->query($sQuery);
  80. }
  81. function deleteModule($aConfig)
  82. {
  83. /*
  84. * Match by path and uri, both unique per module. The vendor is left out:
  85. * the row keeps the vendor it was installed with, and config.php may have
  86. * renamed it since (BoonEx -> UNA INC, ticket #4577).
  87. */
  88. $sQuery = $this->prepare("SELECT `id` FROM `sys_modules` WHERE `path`=? AND `uri`=? LIMIT 1", $aConfig['home_dir'], $aConfig['home_uri']);
  89. $iId = (int)$this->getOne($sQuery);
  90. if(!$iId)
  91. return 0;
  92. $sQuery = $this->prepare("DELETE FROM `sys_modules` WHERE `id`=? LIMIT 1", $iId);
  93. $this->query($sQuery);
  94. $this->deleteModuleTrackFiles($iId);
  95. $this->cleanCache('sys_modules_list');
  96. return $iId;
  97. }
  98. }
  99. /** @} */