BxDolStudioInstallerQuery.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. class BxDolStudioInstallerQuery extends BxDolModuleQuery
  10. {
  11. function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. function getRelationsBy($aParams = array())
  16. {
  17. $sMethod = 'getAll';
  18. $sWhereClause = "";
  19. switch($aParams['type']) {
  20. case 'module':
  21. $sMethod = 'getRow';
  22. $sWhereClause .= $this->prepare(" AND `module`=?", $aParams['value']);
  23. break;
  24. }
  25. $sSql = "SELECT
  26. `id`,
  27. `module`,
  28. `on_install`,
  29. `on_uninstall`,
  30. `on_enable`,
  31. `on_disable`
  32. FROM `sys_modules_relations`
  33. WHERE 1" . $sWhereClause;
  34. return $this->$sMethod($sSql);
  35. }
  36. function insertModule(&$aConfig)
  37. {
  38. $sHelpUrl = isset($aConfig['help_url']) ? $aConfig['help_url'] : '';
  39. $sDependencies = '';
  40. if(isset($aConfig['dependencies']) && is_array($aConfig['dependencies']))
  41. $sDependencies = implode(',', $aConfig['dependencies']);
  42. $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);
  43. $iResult = (int)$this->query($sQuery);
  44. return $iResult > 0 ? (int)$this->lastId() : 0;
  45. }
  46. function insertModuleTrack($iModuleId, &$aFile)
  47. {
  48. $sQuery = $this->prepare("INSERT IGNORE INTO `sys_modules_file_tracks`(`module_id`, `file`, `hash`) VALUES(?, ?, ?)", $iModuleId, $aFile['file'], $aFile['hash']);
  49. $this->query($sQuery);
  50. }
  51. function getModuleTrackFiles($iModuleId)
  52. {
  53. $sQuery = $this->prepare("SELECT `file`, `hash` FROM `sys_modules_file_tracks` WHERE `module_id` = ?", $iModuleId);
  54. return $this->getAllWithKey($sQuery, "file");
  55. }
  56. function deleteModuleTrackFiles($iModuleId)
  57. {
  58. $sQuery = $this->prepare("DELETE FROM `sys_modules_file_tracks` WHERE `module_id` = ?", $iModuleId);
  59. return $this->query($sQuery);
  60. }
  61. function deleteModule($aConfig)
  62. {
  63. $sQuery = $this->prepare("SELECT `id` FROM `sys_modules` WHERE `vendor`=? AND `path`=? LIMIT 1", $aConfig['vendor'], $aConfig['home_dir']);
  64. $iId = (int)$this->getOne($sQuery);
  65. $sQuery = $this->prepare("DELETE FROM `sys_modules` WHERE `vendor`=? AND `path`=? LIMIT 1", $aConfig['vendor'], $aConfig['home_dir']);
  66. $this->query($sQuery);
  67. $this->deleteModuleTrackFiles($iId);
  68. return $iId;
  69. }
  70. }
  71. /** @} */