mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 09:44:55 +02:00
Merge branch 'develop' into feature/phpstan
This commit is contained in:
@@ -1226,7 +1226,8 @@ function clearCache()
|
||||
$configHighscoresPerPage = setting('core.highscores_per_page');
|
||||
$skills = [POT::SKILL_FIST, POT::SKILL_CLUB, POT::SKILL_SWORD, POT::SKILL_AXE, POT::SKILL_DIST, POT::SKILL_SHIELD, POT::SKILL_FISH, POT::SKILL_LEVEL, POT::SKILL__MAGLEVEL, SKILL_FRAGS, SKILL_BALANCE];
|
||||
foreach ($skills as $skill) {
|
||||
$vocations = config('vocations') + ['all'];
|
||||
// config('vocations') may be empty after previous cache clear
|
||||
$vocations = (config('vocations') ?? []) + ['all'];
|
||||
foreach ($vocations as $vocation) {
|
||||
for($page = 0; $page < 10; $page++) {
|
||||
$cacheKey = 'highscores_' . $skill . '_' . strtolower($vocation) . '_' . $page . '_' . $configHighscoresPerPage;
|
||||
|
@@ -134,6 +134,10 @@ $ots = POT::getInstance();
|
||||
$eloquentConnection = null;
|
||||
require_once SYSTEM . 'database.php';
|
||||
|
||||
if ($config_lua_reload) {
|
||||
clearCache();
|
||||
}
|
||||
|
||||
// verify myaac tables exists in database
|
||||
if(!defined('MYAAC_INSTALL') && !$db->hasTable('myaac_account_actions')) {
|
||||
throw new RuntimeException('Seems that the table myaac_account_actions of MyAAC doesn\'t exist in the database. This is a fatal error. You can try to reinstall MyAAC by visiting ' . BASE_URL . 'install');
|
||||
|
@@ -3,7 +3,10 @@
|
||||
// 2024-01-27
|
||||
// change hidden to hide (Eloquent model reserved keyword)
|
||||
|
||||
$db->exec("ALTER TABLE `players` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;");
|
||||
if (!$db->hasColumn('players', 'hide')) {
|
||||
$db->exec("ALTER TABLE `players` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;");
|
||||
}
|
||||
|
||||
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "changelog` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;");
|
||||
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "faq` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;");
|
||||
$db->exec("ALTER TABLE `" . TABLE_PREFIX . "forum_boards` CHANGE `hidden` `hide` TINYINT(1) NOT NULL DEFAULT 0;");
|
||||
|
@@ -61,16 +61,18 @@ if(isset($_POST['deletecharactersave']) && $_POST['deletecharactersave'] == 1) {
|
||||
}
|
||||
}
|
||||
|
||||
$ownerid = 'ownerid';
|
||||
if($db->hasColumn('guilds', 'owner_id'))
|
||||
$ownerid = 'owner_id';
|
||||
$guild = $db->query('SELECT `name` FROM `guilds` WHERE `' . $ownerid . '` = '.$player->getId());
|
||||
if($guild->rowCount() > 0) {
|
||||
$errors[] = 'You cannot delete a character when they own a guild.';
|
||||
if(empty($errors)) {
|
||||
$ownerid = 'ownerid';
|
||||
if ($db->hasColumn('guilds', 'owner_id'))
|
||||
$ownerid = 'owner_id';
|
||||
$guild = $db->query('SELECT `name` FROM `guilds` WHERE `' . $ownerid . '` = ' . $player->getId());
|
||||
if ($guild->rowCount() > 0) {
|
||||
$errors[] = 'You cannot delete a character when they own a guild.';
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($errors)) {
|
||||
//dont show table "delete character" again
|
||||
// don't show table "delete character" again
|
||||
$show_form = false;
|
||||
/** @var OTS_DB_MySQL $db */
|
||||
if ($db->hasColumn('players', 'deletion'))
|
||||
|
@@ -1651,7 +1651,12 @@ Sent by MyAAC,<br/>
|
||||
}
|
||||
}
|
||||
|
||||
return Settings::saveConfig($configToSave, BASE . 'config.local.php');
|
||||
$success = Settings::saveConfig($configToSave, BASE . 'config.local.php');
|
||||
if (!$success) {
|
||||
error('There has been error saving the config.local.php - probably problem with permissions.');
|
||||
}
|
||||
|
||||
return $success;
|
||||
},
|
||||
],
|
||||
];
|
||||
|
62
system/src/Commands/MigrateRunCommand.php
Normal file
62
system/src/Commands/MigrateRunCommand.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC\Commands;
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class MigrateRunCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName('migrate:run')
|
||||
->setDescription('This command runs the migration specified by id')
|
||||
->addArgument('id',
|
||||
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
|
||||
'Id or ids of migration(s)'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$ids = $input->getArgument('id');
|
||||
|
||||
// pre-check
|
||||
// in case one of the migrations doesn't exist - we won't execute any of them
|
||||
foreach ($ids as $id) {
|
||||
if (!$this->migrationExists($id)) {
|
||||
$io->error([
|
||||
"One of the migrations specified doesnt exist: $id",
|
||||
"Please check it and re-run the command",
|
||||
"No migration has been executed",
|
||||
]);
|
||||
|
||||
return Command::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$this->executeMigration($id, $io);
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
private function migrationExists($id): bool {
|
||||
return file_exists(SYSTEM . 'migrations/' . $id . '.php');
|
||||
}
|
||||
|
||||
private function executeMigration($id, $io): void
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db->revalidateCache();
|
||||
|
||||
require SYSTEM . 'migrations/' . $id . '.php';
|
||||
$io->success('Migration ' . $id . ' successfully executed');
|
||||
}
|
||||
}
|
36
system/src/Commands/SettingsResetCommand.php
Normal file
36
system/src/Commands/SettingsResetCommand.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC\Commands;
|
||||
|
||||
use MyAAC\Models\Settings as SettingsModel;
|
||||
use MyAAC\Settings;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SettingsResetCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName('settings:reset')
|
||||
->setDescription('Removes all settings in database');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
if (!$io->confirm('Are you sure you want to reset all settings in database?', false)) {
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
SettingsModel::truncate();
|
||||
|
||||
$settings = Settings::getInstance();
|
||||
$settings->clearCache();
|
||||
|
||||
$io->success('Setting cleared successfully');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
55
system/src/Commands/SettingsSetCommand.php
Normal file
55
system/src/Commands/SettingsSetCommand.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC\Commands;
|
||||
|
||||
use MyAAC\Models\Settings as SettingsModel;
|
||||
use MyAAC\Settings;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SettingsSetCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->setName('settings:set')
|
||||
->setDescription('Updates the setting specified by argument in database')
|
||||
->addArgument('key',
|
||||
InputArgument::REQUIRED,
|
||||
'Setting name/key'
|
||||
)
|
||||
->addArgument('value',
|
||||
InputArgument::REQUIRED,
|
||||
'New value'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$key = $input->getArgument('key');
|
||||
$value = $input->getArgument('value');
|
||||
|
||||
$settings = Settings::getInstance();
|
||||
$settings->clearCache();
|
||||
$settings->load();
|
||||
|
||||
$setting = $settings[$key];
|
||||
if (!isset($setting['value'])) {
|
||||
$io->warning('Settings with this key does not exists');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
// format plugin_name.key
|
||||
// example: core.template
|
||||
$explode = explode('.', $key);
|
||||
|
||||
$settings->updateInDatabase($explode[0], $explode[1], $value);
|
||||
$settings->clearCache();
|
||||
|
||||
$io->success("Setting $key successfully updated");
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
@@ -38,8 +38,7 @@ class Settings implements \ArrayAccess
|
||||
}
|
||||
|
||||
$settings = ModelsSettings::all();
|
||||
foreach ($settings as $setting)
|
||||
{
|
||||
foreach ($settings as $setting) {
|
||||
$this->settingsDatabase[$setting->name][$setting->key] = $setting->value;
|
||||
}
|
||||
|
||||
@@ -93,11 +92,7 @@ class Settings implements \ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
$cache = Cache::getInstance();
|
||||
if ($cache->enabled()) {
|
||||
$cache->delete('settings');
|
||||
}
|
||||
|
||||
$this->clearCache();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,6 +105,8 @@ class Settings implements \ArrayAccess
|
||||
// insert new
|
||||
ModelsSettings::create(['name' => $pluginName, 'key' => $key, 'value' => $value]);
|
||||
}
|
||||
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
public function deleteFromDatabase($pluginName, $key = null)
|
||||
@@ -120,6 +117,8 @@ class Settings implements \ArrayAccess
|
||||
else {
|
||||
ModelsSettings::where('name', $pluginName)->where('key', $key)->delete();
|
||||
}
|
||||
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
public static function display($plugin, $settings): array
|
||||
@@ -465,9 +464,15 @@ class Settings implements \ArrayAccess
|
||||
$ret['value'] = $value;
|
||||
}
|
||||
else {
|
||||
if (!isset($this->settingsFile[$pluginKeyName]['settings'][$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ret['value'] = $this->settingsFile[$pluginKeyName]['settings'][$key]['default'];
|
||||
}
|
||||
|
||||
$ret['key'] = $key;
|
||||
|
||||
if(isset($ret['type'])) {
|
||||
switch($ret['type']) {
|
||||
case 'boolean':
|
||||
@@ -552,10 +557,10 @@ class Settings implements \ArrayAccess
|
||||
$content .= ';' . PHP_EOL;
|
||||
}
|
||||
|
||||
$success = file_put_contents($filename, $content);
|
||||
$success = @file_put_contents($filename, $content);
|
||||
|
||||
// we saved new config.php, need to revalidate cache (only if opcache is enabled)
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
if ($success && function_exists('opcache_invalidate')) {
|
||||
opcache_invalidate($filename);
|
||||
}
|
||||
|
||||
@@ -601,7 +606,15 @@ class Settings implements \ArrayAccess
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getErrors() {
|
||||
public function getErrors(): array {
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
public function clearCache(): void
|
||||
{
|
||||
$cache = Cache::getInstance();
|
||||
if ($cache->enabled()) {
|
||||
$cache->delete('settings');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<link type="text/css" rel="stylesheet" href="{{ constant('BASE_URL') }}tools/css/jquery-ui.min.css">
|
||||
<script src="{{ constant('BASE_URL') }}tools/js/jquery-ui.min.js"></script>
|
||||
<link type="text/css" rel="stylesheet" href="{{ constant('BASE_URL') }}tools/ext/jquery-ui/themes/base/jquery-ui.min.css">
|
||||
<script>
|
||||
var last_id = [];
|
||||
{% for cat, menu in menus %}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
<meta name="keywords" content="{{ setting('core.meta_keywords') }}, myaac, wodzaac" />
|
||||
<meta name="generator" content="MyAAC" />
|
||||
<link rel="stylesheet" type="text/css" href="{{ constant('BASE_URL') }}tools/css/messages.css" />
|
||||
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/js/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/ext/jquery/jquery.min.js"></script>
|
||||
<noscript>
|
||||
<div class="warning" style="text-align: center; font-size: 14px;">
|
||||
Your browser does not support JavaScript or its disabled!<br/>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/js/tinymce/tinymce.min.js"></script>
|
||||
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/ext/tinymce/tinymce.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
let unsaved = false;
|
||||
let lastContent = '';
|
||||
|
Reference in New Issue
Block a user