Clean Expires

Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
This commit is contained in:
Jonas Rittershofer 2020-04-20 13:51:48 +02:00
commit 2cd445d201
12 changed files with 106 additions and 121 deletions

View file

@ -131,7 +131,7 @@ class ApiController extends Controller {
'id' => $form->getId(),
'hash' => $form->getHash(),
'title' => $form->getTitle(),
'expired' => $form->getExpired(),
'expires' => $form->getExpires(),
];
}

View file

@ -173,13 +173,8 @@ class PageController extends Controller {
return new TemplateResponse('forms', 'no.acc.tmpl', []);
}
if ($form->getExpiresTimestamp() === 0) {
$expired = false;
} else {
$expired = time() > $form->getExpiresTimestamp();
}
if ($expired) {
// If form expired, return Expired-Template
if ( ($form->getExpires() !== 0) && (time() > $form->getExpires()) ) {
return new TemplateResponse('forms', 'expired.tmpl');
}

View file

@ -41,8 +41,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setAccess(array $value)
* @method integer getCreated()
* @method void setCreated(integer $value)
* @method integer getExpiresTimestamp()
* @method void setExpiresTimestamp(integer $value)
* @method integer getExpires()
* @method void setExpires(integer $value)
* @method integer getIsAnonymous()
* @method void setIsAnonymous(bool $value)
* @method integer getSubmitOnce()
@ -56,7 +56,7 @@ class Form extends Entity {
protected $ownerId;
protected $accessJson;
protected $created;
protected $expiresTimestamp;
protected $expires;
protected $isAnonymous;
protected $submitOnce;
@ -65,7 +65,7 @@ class Form extends Entity {
*/
public function __construct() {
$this->addType('created', 'integer');
$this->addType('expiresTimestamp', 'integer');
$this->addType('expires', 'integer');
$this->addType('isAnonymous', 'bool');
$this->addType('submitOnce', 'bool');
}
@ -80,20 +80,6 @@ class Form extends Entity {
$this->setAccessJson(json_encode($access));
}
// Get virtual column expires. Set should only be done by setExpiresTimestamp().
public function getExpires(): bool {
return (bool) $this->getExpiresTimestamp();
}
// Get virtual column expired. Set should only be done by setExpiresTimestamp().
public function getExpired(): bool {
if ($this->getExpires()) {
return time() > $this->getExpiresTimestamp();
}
// else - does not expire
return false;
}
// Read full form
public function read() {
return [
@ -102,12 +88,9 @@ class Form extends Entity {
'title' => $this->getTitle(),
'description' => $this->getDescription(),
'ownerId' => $this->getOwnerId(),
'ownerDisplayName' => \OC_User::getDisplayName($this->getOwnerId()),
'created' => $this->getCreated(),
'access' => $this->getAccess(),
'expires' => $this->getExpires(),
'expired' => $this->getExpired(),
'expiresTimestamp' => $this->getExpiresTimestamp(),
'isAnonymous' => $this->getIsAnonymous(),
'submitOnce' => $this->getSubmitOnce()
];

View file

@ -105,7 +105,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
'notnull' => false,
'comment' => 'unix-timestamp',
]);
$table->addColumn('expires_timestamp', Type::INTEGER, [
$table->addColumn('expires', Type::INTEGER, [
'notnull' => false,
'default' => 0,
'comment' => 'unix-timestamp',
@ -237,7 +237,7 @@ class Version010200Date20200323141300 extends SimpleMigrationStep {
'owner_id' => $qb_restore->createNamedParameter($event['owner'], IQueryBuilder::PARAM_STR),
'access_json' => $qb_restore->createNamedParameter($newAccessJSON, IQueryBuilder::PARAM_STR),
'created' => $qb_restore->createNamedParameter($this->convertDateTime($event['created']), IQueryBuilder::PARAM_INT),
'expires_timestamp' => $qb_restore->createNamedParameter($this->convertDateTime($event['expire']), IQueryBuilder::PARAM_INT),
'expires' => $qb_restore->createNamedParameter($this->convertDateTime($event['expire']), IQueryBuilder::PARAM_INT),
'is_anonymous' => $qb_restore->createNamedParameter($event['is_anonymous'], IQueryBuilder::PARAM_BOOL),
'submit_once' => $qb_restore->createNamedParameter($event['unique'], IQueryBuilder::PARAM_BOOL)
]);