Signed-off-by: dartcafe <github@dartcafe.de>
This commit is contained in:
dartcafe 2021-06-21 23:52:14 +02:00
Родитель 7751a511d8
Коммит 2062843b4d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CCE73CEF3035D3C8
6 изменённых файлов: 119 добавлений и 1 удалений

Просмотреть файл

@ -38,6 +38,7 @@
<pre-migration>
<step>OCA\Polls\Migration\RemoveIndices</step>
<step>OCA\Polls\Migration\DeleteInvalidRecords</step>
<step>OCA\Polls\Migration\FixVotes</step>
</pre-migration>
<post-migration>
<step>OCA\Polls\Migration\CreateIndices</step>

Просмотреть файл

@ -139,6 +139,20 @@ class Option extends Entity implements JsonSerializable {
return htmlspecialchars_decode($this->pollOptionText);
}
public function getPollOptionTextEnd(): string {
if ($this->getTimestamp()) {
return date('c', $this->getTimestamp() + $this->getDuration());
}
return htmlspecialchars_decode($this->pollOptionText);
}
public function getPollOptionTextStart(): string {
if ($this->getTimestamp()) {
return date('c', $this->getTimestamp());
}
return htmlspecialchars_decode($this->pollOptionText);
}
public function getOrder(): int {
if ($this->timestamp) {
return $this->getTimestamp();

Просмотреть файл

@ -155,6 +155,22 @@ class OptionMapper extends QBMapper {
return $count;
}
/**
* @return Option[]
*/
public function findOptionsWithDuration(): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('duration', $qb->createNamedParameter(86400, IQueryBuilder::PARAM_INT))
)
->orderBy('order', 'ASC');
return $this->findEntities($qb);
}
public function renameUserId(string $userId, string $replacementName): void {
$query = $this->db->getQueryBuilder();
$query->update($this->getTableName())

Просмотреть файл

@ -214,4 +214,14 @@ class VoteMapper extends QBMapper {
->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)))
->execute();
}
public function fixVoteOptionText(int $pollId, int $optionId, string $searchOptionText, string $replaceOptionText): void {
$query = $this->db->getQueryBuilder();
$query->update($this->getTableName())
->set('vote_option_text', $query->createNamedParameter($replaceOptionText))
->where($query->expr()->eq('vote_option_text', $query->createNamedParameter($searchOptionText)))
->andWhere($query->expr()->eq('poll_id', $query->createNamedParameter($pollId)))
->andWhere($query->expr()->eq('vote_option_id', $query->createNamedParameter($optionId)))
->execute();
}
}

Просмотреть файл

@ -0,0 +1,77 @@
<?php
/**
* @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
* @author René Gieling <github@dartcafe.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Polls\Migration;
use OCA\Polls\Db\LogMapper;
use OCA\Polls\Db\OptionMapper;
use OCA\Polls\Db\VoteMapper;
use OCP\Migration\IRepairStep;
use OCP\Migration\IOutput;
class FixVotes implements IRepairStep {
/** @var LogMapper */
private $logMapper;
/** @var OptionMapper */
private $optionMapper;
/** @var VoteMapper */
private $voteMapper;
public function __construct(
LogMapper $logMapper,
OptionMapper $optionMapper,
VoteMapper $voteMapper
) {
$this->logMapper = $logMapper;
$this->optionMapper = $optionMapper;
$this->voteMapper = $voteMapper;
}
/*
* @inheritdoc
*/
public function getName() {
return 'Polls repairstep - Fix votes with duration options';
}
/**
* @inheritdoc
*
* @return void
*/
public function run(IOutput $output) {
$foundOptions = $this->optionMapper->findOptionsWithDuration();
foreach ($foundOptions as $option) {
$this->voteMapper->fixVoteOptionText(
$option->getPollId(),
$option->getId(),
$option->getPollOptionTextStart(),
$option->getPollOptionText(),
);
}
}
}

Просмотреть файл

@ -114,7 +114,7 @@ export default {
// is the duration divisable through 24 hours without rest
// then we have a day long event (one or multiple days)
// In this case we want to suppress the display of any time information
const dayLongEvent = from.unix() === moment(from).startOf('day').unix() && this.option.duration % 86400 === 0
const dayLongEvent = from.unix() === moment(from).startOf('day').unix() && this.option.duration && this.option.duration % 86400 === 0
const dayModifier = dayLongEvent ? 1 : 0
// modified to date, in case of day long events, a second gets substracted
// to set the begin of the to day to the end of the previous date