Skip to content

Instantly share code, notes, and snippets.

@phalcon
Last active December 15, 2015 05:39
Show Gist options
  • Select an option

  • Save phalcon/5210461 to your computer and use it in GitHub Desktop.

Select an option

Save phalcon/5210461 to your computer and use it in GitHub Desktop.
<?php
use Phalcon\Mvc\Model\Transaction\Manager as TxManager;
class TestTask extends \Phalcon\CLI\Task
{
public function doAction()
{
$config = $GLOBALS['config'];
$this->di->set("transactionManager", new TxManager());
for ($i = 0; $i < 9999999; $i++) {
$this->ins();
}
}
private function ins()
{
$manager = $this->di["transactionManager"];
$transaction = $manager->get();
$project = new \Models\Project();
$project->setTransaction($transaction);
$project->name = 'Test';
$project->description = 'Some text...';
if (true != $project->save()) {
$transaction->rollBack("Unable to save Project. errors:" . print_r($project->getMessages(), true));
}
$target = new \Models\Target();
$target->setTransaction($transaction);
$target->name = 'Target name';
$target->project_id = $project->id;
if (true != $target->save()) {
$transaction->rollBack("Unable to save Target. errors:" . print_r($target->getMessages(), true));
}
$transaction->commit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment