2020-08-24 17:00:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Benzine\ORM\Tests\Models\Base;
|
|
|
|
|
|
|
|
|
|
use Benzine\ORM\Tests\Models;
|
|
|
|
|
use Benzine\ORM\Tests\TableGateways;
|
|
|
|
|
use Benzine\ORM\Tests\Services;
|
|
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
|
use Benzine\ORM\Abstracts\Model as AbstractModel;
|
|
|
|
|
use Benzine\ORM\Interfaces\ModelInterface as ModelInterface;
|
|
|
|
|
use Benzine\App as App;
|
|
|
|
|
|
|
|
|
|
/** ___ __
|
|
|
|
|
* / _ \___ ____ ___ ____ ____/ /
|
|
|
|
|
* / // / _ `/ _ \/ _ `/ -_) __/_/
|
|
|
|
|
* /____/\_,_/_//_/\_, /\__/_/ (_)
|
|
|
|
|
* /___/.
|
|
|
|
|
*
|
|
|
|
|
* Anything in this file is prone to being overwritten!
|
|
|
|
|
*
|
|
|
|
|
* This file was programmatically generated. To modify
|
|
|
|
|
* this classes behaviours, do so in the class that
|
|
|
|
|
* extends this, or modify the Laminator Template!
|
|
|
|
|
*/
|
|
|
|
|
abstract class BaseMigrationsModel extends AbstractModel implements ModelInterface
|
|
|
|
|
{
|
|
|
|
|
// Declare what fields are available on this object
|
|
|
|
|
public const FIELD_VERSION = 'version';
|
|
|
|
|
public const FIELD_MIGRATION_NAME = 'migration_name';
|
|
|
|
|
public const FIELD_START_TIME = 'start_time';
|
|
|
|
|
public const FIELD_END_TIME = 'end_time';
|
|
|
|
|
public const FIELD_BREAKPOINT = 'breakpoint';
|
|
|
|
|
|
|
|
|
|
public const TYPE_VERSION = 'bigint';
|
|
|
|
|
public const TYPE_MIGRATION_NAME = 'varchar';
|
|
|
|
|
public const TYPE_START_TIME = 'timestamp';
|
|
|
|
|
public const TYPE_END_TIME = 'timestamp';
|
|
|
|
|
public const TYPE_BREAKPOINT = 'tinyint';
|
|
|
|
|
|
|
|
|
|
// Constant arrays defined by ENUMs
|
|
|
|
|
|
|
|
|
|
// Constants defined by ENUMs
|
|
|
|
|
|
|
|
|
|
protected array $_primary_keys = [
|
|
|
|
|
'version' => 'version',
|
|
|
|
|
];
|
|
|
|
|
|
2020-08-24 18:11:43 +00:00
|
|
|
// PHPType: int. DBType: bigint.
|
|
|
|
|
// Max Length: 9223372036854775807.
|
2020-08-24 17:00:59 +00:00
|
|
|
protected ?int $version = null;
|
|
|
|
|
|
2020-08-24 18:11:43 +00:00
|
|
|
// PHPType: string. DBType: varchar.
|
2020-08-24 17:00:59 +00:00
|
|
|
protected ?string $migration_name = null;
|
|
|
|
|
|
2020-08-24 18:11:43 +00:00
|
|
|
// PHPType: \DateTime. DBType: timestamp.
|
|
|
|
|
protected ?\DateTime $start_time = null;
|
2020-08-24 17:00:59 +00:00
|
|
|
|
2020-08-24 18:11:43 +00:00
|
|
|
// PHPType: \DateTime. DBType: timestamp.
|
|
|
|
|
protected ?\DateTime $end_time = null;
|
2020-08-24 17:00:59 +00:00
|
|
|
|
2020-08-24 18:11:43 +00:00
|
|
|
// PHPType: int. DBType: tinyint.
|
|
|
|
|
// Max Length: 127.
|
2020-08-24 17:00:59 +00:00
|
|
|
protected ?int $breakpoint = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Caching entities **/
|
|
|
|
|
protected array $cache = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $data an array of a Models\MigrationsModel's properties
|
|
|
|
|
*
|
|
|
|
|
* @return Models\MigrationsModel
|
|
|
|
|
*/
|
|
|
|
|
public static function factory(array $data = [])
|
|
|
|
|
{
|
|
|
|
|
return parent::factory($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns an array describing the properties of this model.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getPropertyMeta(): array
|
|
|
|
|
{
|
2020-08-24 18:11:43 +00:00
|
|
|
|
2020-08-24 17:00:59 +00:00
|
|
|
return [
|
|
|
|
|
self::FIELD_VERSION => [
|
|
|
|
|
'type' => self::TYPE_VERSION,
|
|
|
|
|
],
|
|
|
|
|
self::FIELD_MIGRATION_NAME => [
|
|
|
|
|
'type' => self::TYPE_MIGRATION_NAME,
|
|
|
|
|
'length' => 100,
|
|
|
|
|
],
|
|
|
|
|
self::FIELD_START_TIME => [
|
|
|
|
|
'type' => self::TYPE_START_TIME,
|
|
|
|
|
],
|
|
|
|
|
self::FIELD_END_TIME => [
|
|
|
|
|
'type' => self::TYPE_END_TIME,
|
|
|
|
|
],
|
|
|
|
|
self::FIELD_BREAKPOINT => [
|
|
|
|
|
'type' => self::TYPE_BREAKPOINT,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion(): ?int
|
|
|
|
|
{
|
|
|
|
|
return $this->version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-24 18:11:43 +00:00
|
|
|
* @param int|null $version
|
2020-08-24 17:00:59 +00:00
|
|
|
*
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setVersion(int $version = null): self
|
|
|
|
|
{
|
|
|
|
|
$this->version = $version;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getMigration_name(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->migration_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-24 18:11:43 +00:00
|
|
|
* @param string|null $migration_name
|
2020-08-24 17:00:59 +00:00
|
|
|
*
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setMigration_name(string $migration_name = null): self
|
|
|
|
|
{
|
|
|
|
|
$this->migration_name = $migration_name;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 18:11:43 +00:00
|
|
|
public function getStart_time(): ?\DateTime
|
2020-08-24 17:00:59 +00:00
|
|
|
{
|
|
|
|
|
return $this->start_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-24 18:11:43 +00:00
|
|
|
* @param \DateTime|null $start_time
|
2020-08-24 17:00:59 +00:00
|
|
|
*
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
2020-08-24 18:11:43 +00:00
|
|
|
public function setStart_time(\DateTime $start_time = null): self
|
2020-08-24 17:00:59 +00:00
|
|
|
{
|
|
|
|
|
$this->start_time = $start_time;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 18:11:43 +00:00
|
|
|
public function getEnd_time(): ?\DateTime
|
2020-08-24 17:00:59 +00:00
|
|
|
{
|
|
|
|
|
return $this->end_time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-24 18:11:43 +00:00
|
|
|
* @param \DateTime|null $end_time
|
2020-08-24 17:00:59 +00:00
|
|
|
*
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
2020-08-24 18:11:43 +00:00
|
|
|
public function setEnd_time(\DateTime $end_time = null): self
|
2020-08-24 17:00:59 +00:00
|
|
|
{
|
|
|
|
|
$this->end_time = $end_time;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getBreakpoint(): ?int
|
|
|
|
|
{
|
|
|
|
|
return $this->breakpoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-24 18:11:43 +00:00
|
|
|
* @param int|null $breakpoint
|
2020-08-24 17:00:59 +00:00
|
|
|
*
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setBreakpoint(int $breakpoint = null): self
|
|
|
|
|
{
|
|
|
|
|
$this->breakpoint = $breakpoint;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
|
*/
|
|
|
|
|
public function save(): Models\MigrationsModel
|
|
|
|
|
{
|
|
|
|
|
/** @var TableGateways\MigrationsTableGateway $tableGateway */
|
|
|
|
|
$tableGateway = App::DI(TableGateways\MigrationsTableGateway::class);
|
|
|
|
|
|
|
|
|
|
return $tableGateway->save($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destroy the current record.
|
|
|
|
|
* Returns the number of affected rows.
|
|
|
|
|
*
|
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(): int
|
|
|
|
|
{
|
|
|
|
|
/** @var TableGateways\MigrationsTableGateway $tableGateway */
|
|
|
|
|
$tableGateway = App::DI(TableGateways\MigrationsTableGateway::class);
|
|
|
|
|
|
|
|
|
|
return $tableGateway->delete($this->getPrimaryKeys_dbColumns());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destroy the current record, and any dependencies upon it, recursively.
|
|
|
|
|
* Returns the number of affected rows.
|
|
|
|
|
*
|
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
|
*/
|
|
|
|
|
public function destroyThoroughly(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides an array of all properties in this model.
|
|
|
|
|
*
|
|
|
|
|
* @return string[]
|
|
|
|
|
*/
|
|
|
|
|
public function getListOfProperties(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'version' => 'version',
|
|
|
|
|
'migration_name' => 'migration_name',
|
|
|
|
|
'start_time' => 'start_time',
|
|
|
|
|
'end_time' => 'end_time',
|
|
|
|
|
'breakpoint' => 'breakpoint',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Take an input array $data, and turn that array into a hydrated object.
|
|
|
|
|
*
|
|
|
|
|
* @param array $data dehydated object array
|
|
|
|
|
*
|
|
|
|
|
* @return Models\MigrationsModel
|
|
|
|
|
*/
|
|
|
|
|
public function exchangeArray(array $data): self
|
|
|
|
|
{
|
2020-08-24 18:11:43 +00:00
|
|
|
return $this
|
|
|
|
|
->setVersion($data['version'] ?? $data['Version'])
|
|
|
|
|
->setMigration_name($data['migration_name'] ?? $data['Migration_name'])
|
|
|
|
|
->setStart_time(\DateTime::createFromFormat("Y-m-d H:i:s", $data['start_time'] ?? $data['Start_time']))
|
|
|
|
|
->setEnd_time(\DateTime::createFromFormat("Y-m-d H:i:s", $data['end_time'] ?? $data['End_time']))
|
|
|
|
|
->setBreakpoint($data['breakpoint'] ?? $data['Breakpoint'])
|
|
|
|
|
;
|
2020-08-24 17:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|