BxDolStudioInstallerQuery.php 3.3 KB

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