Commit 66fb94f3 authored by Karamel's avatar Karamel
Browse files

Factorize write/update dates in DoctrineMainMutableModel

parent 4e32cf10
......@@ -103,6 +103,7 @@ $filesToCheck = [
'src/lib/System/SysModules/Database/SingleDB.php',
'src/lib/System/SysModules/Database/InifileDB.php',
'src/lib/System/DAO/DoctrineModel.php',
'src/lib/System/DAO/DoctrineMainMutableModel.php',
'src/lib/System/DAO/DAOFactory.php',
'src/lib/System/DAO/DBException.php',
'src/lib/System/DAO/DAOCondition.php',
......
......@@ -22,17 +22,16 @@ namespace Pasteque\Server\Model;
use \Pasteque\Server\Model\Field\IntField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class CashRegister
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="cashregisters")
*/
class CashRegister extends DoctrineMainModel
class CashRegister extends DoctrineMainMutableModel
{
protected static function getDirectFieldNames() {
return [
......@@ -136,44 +135,4 @@ class CashRegister extends DoctrineMainModel
$this->setNextSessionId($this->getNextSessionId() + 1);
return $this->getNextSessionId();
}
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist() {
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate() {
$this->setUpdatedAt(new \DateTime());
}
}
......@@ -23,17 +23,16 @@ namespace Pasteque\Server\Model;
use \Pasteque\Server\Model\Field\IntField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class Category
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="categories")
*/
class Category extends DoctrineMainModel
class Category extends DoctrineMainMutableModel
{
protected static function getDirectFieldNames() {
......@@ -133,44 +132,4 @@ class Category extends DoctrineMainModel
protected $dispOrder = 0;
public function getDispOrder() { return $this->dispOrder; }
public function setDispOrder($dispOrder) { $this->dispOrder = $dispOrder; }
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist()
{
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate()
{
$this->setUpdatedAt(new \DateTime());
}
}
......@@ -25,17 +25,16 @@ namespace Pasteque\Server\Model;
use \Pasteque\Server\Model\Field\BoolField;
use \Pasteque\Server\Model\Field\FloatField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class Currency
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="currencies")
*/
class Currency extends DoctrineMainModel
class Currency extends DoctrineMainMutableModel
{
protected static function getDirectFieldNames() {
return [
......@@ -166,43 +165,4 @@ class Currency extends DoctrineMainModel
/** Alias for getVisible (the latter is required for Doctrine) */
public function isVisible() { return $this->getVisible(); }
public function setVisible($visible) { $this->visible = $visible; }
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist()
{
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate()
{
$this->setUpdatedAt(new \DateTime());
}
}
......@@ -26,17 +26,16 @@ use \Pasteque\Server\Model\Field\DateField;
use \Pasteque\Server\Model\Field\FloatField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DateUtils;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class Customer
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="customers")
*/
class Customer extends DoctrineMainModel
class Customer extends DoctrineMainMutableModel
{
protected static function getDirectFieldNames() {
return ['id',
......@@ -354,46 +353,6 @@ class Customer extends DoctrineMainModel
public function hasImage() { return $this->getHasImage(); }
public function setHasImage($hasImage) { $this->hasImage = $hasImage; }
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist()
{
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate()
{
$this->setUpdatedAt(new \DateTime());
}
/** Add some old deprecated virtual fields */
public function toStruct() {
$struct = parent::toStruct();
......@@ -402,6 +361,4 @@ class Customer extends DoctrineMainModel
$struct['expireDate'] = DateUtils::toTimestamp($this->getExpireDate());
return $struct;
}
}
......@@ -26,7 +26,7 @@ use \Pasteque\Server\Model\Field\DateField;
use \Pasteque\Server\Model\Field\FloatField;
use \Pasteque\Server\Model\Field\IntField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
*
......@@ -34,10 +34,9 @@ use \Pasteque\Server\System\DAO\DoctrineMainModel;
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="discounts")
*/
class Discount extends DoctrineMainModel
class Discount extends DoctrineMainMutableModel
{
protected static function getDirectFieldNames() {
return ['id',
......@@ -141,44 +140,4 @@ class Discount extends DoctrineMainModel
protected $dispOrder = 0;
public function getDispOrder() { return $this->dispOrder; }
public function setDispOrder($dispOrder) { $this->dispOrder = $dispOrder; }
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist() {
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate() {
$this->setUpdatedAt(new \DateTime());
}
}
......@@ -23,17 +23,16 @@ namespace Pasteque\Server\Model;
use \Pasteque\Server\Model\Field\FloatField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class DiscountProfile
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="discountprofiles")
*/
class DiscountProfile extends DoctrineMainModel
class DiscountProfile extends DoctrineMainMutableModel
{
protected static function getDirectFieldNames() {
return [new StringField('label'),
......@@ -82,43 +81,4 @@ class DiscountProfile extends DoctrineMainModel
private $rate;
public function getRate() { return $this->rate; }
public function setRate($rate) { $this->rate = $rate; }
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist() {
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate() {
$this->setUpdatedAt(new \DateTime());
}
}
......@@ -23,17 +23,16 @@ namespace Pasteque\Server\Model;
use \Pasteque\Server\Model\Field\IntField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class Floor
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="floors")
*/
class Floor extends DoctrineMainModel
class Floor extends DoctrineMainMutableModel
{
protected static function getDirectFieldNames() {
return ['id', new StringField('label'), new IntField('dispOrder')];
......@@ -124,42 +123,4 @@ class Floor extends DoctrineMainModel
$this->places->removeElement($place);
$place->setFloor(null);
}
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist() {
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate() {
$this->setUpdatedAt(new \DateTime());
}
}
......@@ -25,7 +25,7 @@ use \Pasteque\Server\Model\PaymentMode;
use \Pasteque\Server\Model\PaymentModeValue;
use \Pasteque\Server\Model\Field\EnumField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class Image.
......@@ -38,10 +38,9 @@ use \Pasteque\Server\System\DAO\DoctrineMainModel;
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="images")
*/
class Image extends DoctrineMainModel
class Image extends DoctrineMainMutableModel
{
const MODEL_CATEGORY = 'category';
const MODEL_PRODUCT = 'product';
......@@ -170,42 +169,6 @@ class Image extends DoctrineMainModel
public function getImage() { return $this->image; }
public function setImage($image) { $this->image = $image; }
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist() {
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate() {
$this->setUpdatedAt(new \DateTime());
}
public function toStruct() {
// Handle base64 encoding of binary image
$struct = parent::toStruct();
......
......@@ -24,17 +24,16 @@ namespace Pasteque\Server\Model;
use \Pasteque\Server\Model\Field\BoolField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class Option. Non-structured general options.
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="options")
*/
class Option extends DoctrineMainModel
class Option extends DoctrineMainMutableModel
{
protected static function getDirectFieldNames() {
// 'key' and 'value' are keywords in mysql and crash Doctrine
......@@ -86,30 +85,4 @@ class Option extends DoctrineMainModel
protected $content = '';
public function getContent() { return $this->content; }
public function setContent($content) { $this->content = $content; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }
public function setUpdatedAt($datetime) { $this->updatedAt = $datetime; }
/**
* @PrePersist()
*/
public function doStuffOnPrePersist() {
$this->setCreatedAt(new \DateTime());
}
/**
* @PreUpdate()
*/
public function doStuffOnPreUpdate() {
$this->setUpdatedAt(new \DateTime());
}
}
......@@ -24,17 +24,16 @@ namespace Pasteque\Server\Model;
use \Pasteque\Server\Model\Field\BoolField;
use \Pasteque\Server\Model\Field\IntField;
use \Pasteque\Server\Model\Field\StringField;
use \Pasteque\Server\System\DAO\DoctrineMainModel;
use \Pasteque\Server\System\DAO\DoctrineMainMutableModel;
/**
* Class PaymentMode
* @package Pasteque
* @SWG\Definition(type="object")
* @Entity
* @HasLifecycleCallbacks
* @Table(name="paymentmodes")
*/
class PaymentMode extends DoctrineMainModel
class PaymentMode extends DoctrineMainMutableModel
{
public function __toString() { return $this->getReference(); }
......@@ -267,43 +266,4 @@ class PaymentMode extends DoctrineMainModel
$this->setReference($struct['code']);
}
}
/**
* Date and time of creation
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="created_at")
*/
protected $createdAt;
public function getCreatedAt() { return $this->createdAt; }
public function setCreatedAt($datetime) { $this->createdAt = $datetime; }
/**
* Date and time of the last update
* @var string|null
* @SWG\Property(format="date-time")
* @Column(type="datetime", name="updated_at", nullable=true)
*/
protected $updatedAt;
public function getUpdatedAt() { return $this->updatedAt; }