Merge branch 'master' into tax

This commit is contained in:
Etienne Roudeix
2013-10-11 11:13:41 +02:00
32 changed files with 932 additions and 131 deletions

View File

@@ -1071,6 +1071,10 @@ abstract class Country implements ActiveRecordInterface
$modifiedColumns = array();
$index = 0;
$this->modifiedColumns[] = CountryTableMap::ID;
if (null !== $this->id) {
throw new PropelException('Cannot insert a value for auto-increment primary key (' . CountryTableMap::ID . ')');
}
// check the columns in natural order for more readable SQL queries
if ($this->isColumnModified(CountryTableMap::ID)) {
@@ -1140,6 +1144,13 @@ abstract class Country implements ActiveRecordInterface
throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
}
try {
$pk = $con->lastInsertId();
} catch (Exception $e) {
throw new PropelException('Unable to get autoincrement id.', 0, $e);
}
$this->setId($pk);
$this->setNew(false);
}
@@ -1439,7 +1450,6 @@ abstract class Country implements ActiveRecordInterface
*/
public function copyInto($copyObj, $deepCopy = false, $makeNew = true)
{
$copyObj->setId($this->getId());
$copyObj->setAreaId($this->getAreaId());
$copyObj->setIsocode($this->getIsocode());
$copyObj->setIsoalpha2($this->getIsoalpha2());
@@ -1475,6 +1485,7 @@ abstract class Country implements ActiveRecordInterface
if ($makeNew) {
$copyObj->setNew(true);
$copyObj->setId(NULL); // this is a auto-increment column, so set to default value
}
}

View File

@@ -2,8 +2,59 @@
namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Core\Event\Country\CountryEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\Country as BaseCountry;
class Country extends BaseCountry {
class Country extends BaseCountry
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
public function toggleDefault()
{
CountryQuery::create()
->filterByByDefault(1)
->update(array('ByDefault' => 0));
$this
->setByDefault(1)
->save();
}
public function preInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECOUNTRY, new CountryEvent($this));
return true;
}
public function postInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_CREATECOUNTRY, new CountryEvent($this));
}
public function preUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATECOUNTRY, new CountryEvent($this));
return true;
}
public function postUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_UPDATECOUNTRY, new CountryEvent($this));
}
public function preDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_DELETECOUNTRY, new CountryEvent($this));
return true;
}
public function postDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETECOUNTRY, new CountryEvent($this));
}
}

View File

@@ -167,7 +167,7 @@ class CountryTableMap extends TableMap
$this->setPhpName('Country');
$this->setClassName('\\Thelia\\Model\\Country');
$this->setPackage('Thelia.Model');
$this->setUseIdGenerator(false);
$this->setUseIdGenerator(true);
// columns
$this->addPrimaryKey('ID', 'Id', 'INTEGER', true, null, null);
$this->addForeignKey('AREA_ID', 'AreaId', 'INTEGER', 'area', 'ID', false, null, null);
@@ -466,6 +466,10 @@ class CountryTableMap extends TableMap
$criteria = $criteria->buildCriteria(); // build Criteria from Country object
}
if ($criteria->containsKey(CountryTableMap::ID) && $criteria->keyContainsValue(CountryTableMap::ID) ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('.CountryTableMap::ID.')');
}
// Set the correct dbName
$query = CountryQuery::create()->mergeWith($criteria);