Take into account the limit for the volume of uploaded files

This commit is contained in:
Visman 2023-07-11 23:57:06 +07:00
parent 38fbadc409
commit 62b335542e
5 changed files with 32 additions and 1 deletions

View file

@ -15,6 +15,7 @@ use ForkBB\Core\Image;
use ForkBB\Models\Manager;
use ForkBB\Models\Post\Post;
use ForkBB\Models\PM\PPost;
use ForkBB\Models\User\User;
use PDO;
use RuntimeException;
@ -222,4 +223,16 @@ class Attachments extends Manager
return;
}
public function recalculate(User $user)
{
$vars = [
':uid' => $user->id,
];
$query = 'SELECT SUM(size_kb) FROM ::attachments WHERE uid=?i:uid';
$user->u_up_size_mb = (int) round($this->c->DB->query($query, $vars)->fetchColumn() / 1024);
$this->c->users->update($user); //???? оптимизировать?
}
}

View file

@ -1184,6 +1184,7 @@ class Install extends Admin
'last_report_id' => ['INT(10) UNSIGNED', false, 0],
'ip_check_type' => ['TINYINT UNSIGNED', false, 0],
'login_ip_cache' => ['VARCHAR(255)', false, ''],
'u_up_size_mb' => ['INT(10) UNSIGNED', false, 0],
],
'PRIMARY KEY' => ['id'],
'UNIQUE KEYS' => [

View file

@ -715,4 +715,14 @@ class Update extends Admin
return null;
}
/**
* rev.60 to rev.61
*/
protected function stageNumber60(array $args): ?int
{
$this->c->DB->addField('::users', 'u_up_size_mb', 'INT(10) UNSIGNED', false, 0);
return null;
}
}

View file

@ -315,12 +315,14 @@ trait PostValidatorTrait
}
$result = "\n";
$calc = false;
foreach ($v->attachments as $file) {
$data = $this->c->attachments->addFile($file);
if (\is_array($data)) {
$name = $file->name();
$calc = true;
if ($data['image']) {
$result .= "[img]{$data['url']}[/img]\n"; // ={$name}
@ -330,6 +332,10 @@ trait PostValidatorTrait
}
}
if ($calc) {
$this->c->attachments->recalculate($this->user);
}
return $result;
}
}

View file

@ -154,6 +154,7 @@ class Users extends Rules
&& 1 === $this->user->g_post_links // ???? может быть локальные ссылки разрешить в постах?
&& ! empty($this->user->g_up_ext)
&& $this->user->g_up_size_kb > 0
&& $this->user->g_up_limit_mb > 0;
&& $this->user->g_up_limit_mb > 0
&& $this->user->u_up_size_mb < $this->user->g_up_limit_mb;
}
}