2024.8.23
Loading...
Searching...
No Matches
class.app.phpmyadmin.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class AppPhpmyadmin
12 *
13 * This class represents the phpMyAdmin application module in the Bearsampp application.
14 * It extends the Module class and provides functionalities specific to phpMyAdmin,
15 * such as configuration management and version handling.
16 */
17class AppPhpmyadmin extends Module
18{
19 /**
20 * Constant for the configuration key representing the phpMyAdmin version.
21 */
22 const ROOT_CFG_VERSION = 'phpmyadminVersion';
23
24 /**
25 * Constant for the configuration key representing the phpMyAdmin configuration file.
26 */
27 const LOCAL_CFG_CONF = 'phpmyadminConf';
28
29 /**
30 * @var string The path to the phpMyAdmin configuration file.
31 */
32 private $conf;
33
34 /**
35 * Constructor for the AppPhpmyadmin class.
36 *
37 * @param string $id The ID of the module.
38 * @param string $type The type of the module.
39 */
40 public function __construct($id, $type) {
41 Util::logInitClass($this);
42 $this->reload($id, $type);
43 }
44
45 /**
46 * Reloads the module configuration based on the provided ID and type.
47 *
48 * @param string|null $id The ID of the module. If null, the current ID is used.
49 * @param string|null $type The type of the module. If null, the current type is used.
50 */
51 public function reload($id = null, $type = null) {
54
55 // This makes name and version the values in bearsampp.conf
56 $this->name = $bearsamppLang->getValue(Lang::PHPMYADMIN);
57 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
58 parent::reload($id, $type);
59
60 if ($this->bearsamppConfRaw !== false) {
61 $this->conf = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_CONF];
62 }
63
64 if (!$this->enable) {
65 Util::logInfo($this->name . ' is not enabled!');
66 return;
67 }
68 if (!is_dir($this->currentPath)) {
69 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
70 }
71 if (!is_dir($this->symlinkPath)) {
72 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
73 return;
74 }
75 if (!is_file($this->bearsamppConf)) {
76 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
77 }
78 if (!is_file($this->conf)) {
79 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->conf));
80 }
81 }
82
83 /**
84 * Updates the configuration of the phpMyAdmin module.
85 *
86 * @param string|null $version The version to update to. If null, the current version is used.
87 * @param int $sub The sub-level for logging indentation.
88 * @param bool $showWindow Whether to show a window during the update process.
89 * @return bool True if the update was successful, false otherwise.
90 */
91 protected function updateConfig($version = null, $sub = 0, $showWindow = false) {
93
94 if (!$this->enable) {
95 return true;
96 }
97
98 $version = $version == null ? $this->version : $version;
99 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
100
101 $alias = $bearsamppRoot->getAliasPath() . '/phpmyadmin.conf';
102 if (is_file($alias)) {
103 Util::replaceInFile($alias, array(
104 '/^Alias\s\/phpmyadmin\s.*/' => 'Alias /phpmyadmin "' . $this->getSymlinkPath() . '/"',
105 '/^<Directory\s.*/' => '<Directory "' . $this->getSymlinkPath() . '/">',
106 ));
107 } else {
108 Util::logError($this->getName() . ' alias not found : ' . $alias);
109 }
110
111 if ($bearsamppBins->getMysql()->isEnable()) {
112 Util::replaceInFile($this->getConf(), array(
113 '/^\$mysqlPort\s=\s(\d+)/' => '$mysqlPort = ' . $bearsamppBins->getMysql()->getPort() . ';',
114 '/^\$mysqlRootUser\s=\s/' => '$mysqlRootUser = \'' . $bearsamppBins->getMysql()->getRootUser() . '\';',
115 '/^\$mysqlRootPwd\s=\s/' => '$mysqlRootPwd = \'' . $bearsamppBins->getMysql()->getRootPwd() . '\';'
116 ));
117 }
118 if ($bearsamppBins->getMariadb()->isEnable()) {
119 Util::replaceInFile($this->getConf(), array(
120 '/^\$mariadbPort\s=\s(\d+)/' => '$mariadbPort = ' . $bearsamppBins->getMariadb()->getPort() . ';',
121 '/^\$mariadbRootUser\s=\s/' => '$mariadbRootUser = \'' . $bearsamppBins->getMariadb()->getRootUser() . '\';',
122 '/^\$mariadbRootPwd\s=\s/' => '$mariadbRootPwd = \'' . $bearsamppBins->getMariadb()->getRootPwd() . '\';'
123 ));
124 }
125
126 return true;
127 }
128
129 /**
130 * Sets the version of the phpMyAdmin module.
131 *
132 * @param string $version The version to set.
133 */
134 public function setVersion($version) {
135 global $bearsamppConfig;
136 $this->version = $version;
137 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
138 $this->reload();
139 }
140
141 /**
142 * Gets the path to the phpMyAdmin configuration file.
143 *
144 * @return string The path to the configuration file.
145 */
146 public function getConf() {
147 return $this->conf;
148 }
149}
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
reload($id=null, $type=null)
updateConfig($version=null, $sub=0, $showWindow=false)
const ERROR_FILE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const PHPMYADMIN
static logReloadClass($classInstance)
static replaceInFile($path, $replaceList)
static logError($data, $file=null)
static logDebug($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26