Merge branch 'develop' into feature/phpstan

This commit is contained in:
slawkens
2024-02-18 12:12:19 +01:00
88 changed files with 633 additions and 3495 deletions

View File

@@ -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;

View File

@@ -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');

View File

@@ -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;");

View File

@@ -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'))

View File

@@ -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;
},
],
];

View 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');
}
}

View 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;
}
}

View 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;
}
}

View File

@@ -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');
}
}
}

View File

@@ -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 %}

View File

@@ -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/>

View File

@@ -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 = '';