Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7eb6151111 | |||
| 33db0bc463 |
+5
-5
@@ -40,7 +40,7 @@ use validator\Validator;
|
|||||||
*
|
*
|
||||||
* @package Kiri\Abstracts
|
* @package Kiri\Abstracts
|
||||||
*
|
*
|
||||||
* @property bool $isCreate
|
* @property bool $isNowExample
|
||||||
* @property Application $container
|
* @property Application $container
|
||||||
* @property EventDispatch $eventDispatch
|
* @property EventDispatch $eventDispatch
|
||||||
* @property array $attributes
|
* @property array $attributes
|
||||||
@@ -229,7 +229,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
|||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getIsCreate(): bool
|
public function getIsNowExample(): bool
|
||||||
{
|
{
|
||||||
return $this->isNewExample === TRUE;
|
return $this->isNewExample === TRUE;
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
|||||||
* @param bool $bool
|
* @param bool $bool
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setIsCreate(bool $bool = FALSE): static
|
public function setIsNowExample(bool $bool = FALSE): static
|
||||||
{
|
{
|
||||||
$this->isNewExample = $bool;
|
$this->isNewExample = $bool;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -629,7 +629,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
|||||||
{
|
{
|
||||||
$this->_attributes = $value;
|
$this->_attributes = $value;
|
||||||
$this->_oldAttributes = $value;
|
$this->_oldAttributes = $value;
|
||||||
$this->setIsCreate(FALSE);
|
$this->setIsNowExample(FALSE);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1058,7 +1058,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
|
|||||||
$model = duplicate(static::class);
|
$model = duplicate(static::class);
|
||||||
$model->_attributes = $data;
|
$model->_attributes = $data;
|
||||||
$model->_oldAttributes = $data;
|
$model->_oldAttributes = $data;
|
||||||
$model->setIsCreate(false);
|
$model->setIsNowExample(false);
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-12
@@ -75,24 +75,18 @@ class Connection extends Component
|
|||||||
public Schema $_schema;
|
public Schema $_schema;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var EventProvider
|
|
||||||
*/
|
|
||||||
#[Inject(EventProvider::class)]
|
|
||||||
public EventProvider $eventProvider;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute by __construct
|
* execute by __construct
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->eventProvider->on(OnWorkerStop::class, [$this, 'clear_connection'], 0);
|
$eventProvider = Kiri::getDi()->get(EventProvider::class);
|
||||||
$this->eventProvider->on(OnWorkerExit::class, [$this, 'clear_connection'], 0);
|
$eventProvider->on(OnWorkerStop::class, [$this, 'clear_connection'], 0);
|
||||||
$this->eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
|
$eventProvider->on(OnWorkerExit::class, [$this, 'clear_connection'], 0);
|
||||||
$this->eventProvider->on(Rollback::class, [$this, 'rollback'], 0);
|
$eventProvider->on(BeginTransaction::class, [$this, 'beginTransaction'], 0);
|
||||||
$this->eventProvider->on(Commit::class, [$this, 'commit'], 0);
|
$eventProvider->on(Rollback::class, [$this, 'rollback'], 0);
|
||||||
|
$eventProvider->on(Commit::class, [$this, 'commit'], 0);
|
||||||
|
|
||||||
if (Db::transactionsActive()) {
|
if (Db::transactionsActive()) {
|
||||||
$this->beginTransaction();
|
$this->beginTransaction();
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use Kiri\Application;
|
|||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Kiri;
|
use Kiri\Kiri;
|
||||||
use Note\Inject;
|
|
||||||
use Server\Events\OnWorkerStart;
|
use Server\Events\OnWorkerStart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,13 +23,6 @@ class DatabasesProviders extends Providers
|
|||||||
private array $_pooLength = ['min' => 0, 'max' => 1];
|
private array $_pooLength = ['min' => 0, 'max' => 1];
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var EventProvider
|
|
||||||
*/
|
|
||||||
#[Inject(EventProvider::class)]
|
|
||||||
public EventProvider $eventProvider;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Application $application
|
* @param Application $application
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ class Model extends Base\Model
|
|||||||
if (empty($select)) {
|
if (empty($select)) {
|
||||||
$select = duplicate(static::class);
|
$select = duplicate(static::class);
|
||||||
$select->attributes = $attributes;
|
$select->attributes = $attributes;
|
||||||
|
$select->setIsNowExample(true);
|
||||||
if (!$select->save()) {
|
if (!$select->save()) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
return $logger->addError($select->getLastError(), 'mysql');
|
return $logger->addError($select->getLastError(), 'mysql');
|
||||||
|
|||||||
Reference in New Issue
Block a user