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 DolphinStudio Dolphin 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. $sProductUrl = isset($aConfig['product_url']) ? $aConfig['product_url'] : '';
  40. $sUpdateUrl = isset($aConfig['update_url']) ? $aConfig['update_url'] : '';
  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`, `product_url`, `update_url`, `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'], $sProductUrl, $sUpdateUrl, $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. /** @} */