Browse Source

add magnet form lock to prevent moderation overwrite

main
ghost 1 year ago
parent
commit
64e841ec4c
  1. BIN
      database/yggtracker.mwb
  2. 2
      src/config/app.php.example
  3. 24
      src/library/database.php
  4. 14
      src/public/edit.php

BIN
database/yggtracker.mwb

Binary file not shown.

2
src/config/app.php.example

@ -78,6 +78,8 @@ define('MAGNET_DEFAULT_PUBLIC', false); @@ -78,6 +78,8 @@ define('MAGNET_DEFAULT_PUBLIC', false);
define('MAGNET_DEFAULT_COMMENTS', true);
define('MAGNET_DEFAULT_SENSITIVE', false);
define('MAGNET_EDITOR_LOCK_TIMEOUT', 60*60);
define('MAGNET_META_TITLE_MIN_LENGTH', 10);
define('MAGNET_META_DESCRIPTION_MIN_LENGTH', 0);

24
src/library/database.php

@ -839,7 +839,6 @@ class Database { @@ -839,7 +839,6 @@ class Database {
return $this->_db->lastInsertId();
}
public function deleteMagnetToExactSourceByMagnetId(int $magnetId) : int {
$this->_debug->query->delete->total++;
@ -938,6 +937,29 @@ class Database { @@ -938,6 +937,29 @@ class Database {
return $this->addMagnetToKeywordTopic($magnetId, $keywordTopicId);
}
// Magnet lock
public function addMagnetLock(int $magnetId, int $userId, int $timeAdded) : int {
$this->_debug->query->insert->total++;
$query = $this->_db->prepare('INSERT INTO `magnetLock` SET `magnetId` = ?, `userId` = ?, `timeAdded` = ?');
$query->execute([$magnetId, $userId, $timeAdded]);
return $this->_db->lastInsertId();
}
public function findLastMagnetLock(int $magnetId) {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `magnetLock` WHERE `magnetId` = ? ORDER BY `magnetLockId` DESC LIMIT 1');
$query->execute([$magnetId]);
return $query->fetch();
}
// Magnet comment
public function getMagnetCommentsTotal(int $magnetId) : int {

14
src/public/edit.php

@ -155,6 +155,20 @@ else if (!($user->address == $db->getUser($magnet->userId)->address || in_array( @@ -155,6 +155,20 @@ else if (!($user->address == $db->getUser($magnet->userId)->address || in_array(
// Process form
else {
// Validate magnet lock
if ($lastMagnetLock = $db->findLastMagnetLock($magnet->magnetId))
{
if ($lastMagnetLock->userId != $user->userId &&
$lastMagnetLock->timeAdded > time() - MAGNET_EDITOR_LOCK_TIMEOUT)
{
$response->success = false;
$response->message = _('This form have opened by owner or moderator, to prevent overwriting, try attempt later!');
}
}
// Lock form for moderators
$db->addMagnetLock($magnet->magnetId, $user->userId, time());
// Update form
if (!empty($_POST)) {

Loading…
Cancel
Save