Changeset 59
- Timestamp:
- 26.12.2011 14:26:02 (5 months ago)
- Location:
- branches/Credentials/app
- Files:
-
- 20 edited
-
config/classmap-syscpng-conf.php (modified) (1 diff)
-
config/syscpng-conf.php (modified) (2 diffs)
-
lib/propelom/map/CredentialTableMap.php (modified) (1 diff)
-
lib/propelom/map/RoleTableMap.php (modified) (1 diff)
-
lib/propelom/map/UserTableMap.php (modified) (1 diff)
-
lib/propelom/om/BaseCredential.php (modified) (19 diffs)
-
lib/propelom/om/BaseCredentialPeer.php (modified) (3 diffs)
-
lib/propelom/om/BaseCredentialQuery.php (modified) (22 diffs)
-
lib/propelom/om/BaseRole.php (modified) (17 diffs)
-
lib/propelom/om/BaseRoleCredential.php (modified) (6 diffs)
-
lib/propelom/om/BaseRoleCredentialPeer.php (modified) (10 diffs)
-
lib/propelom/om/BaseRoleCredentialQuery.php (modified) (19 diffs)
-
lib/propelom/om/BaseRolePeer.php (modified) (3 diffs)
-
lib/propelom/om/BaseRoleQuery.php (modified) (20 diffs)
-
lib/propelom/om/BaseUser.php (modified) (33 diffs)
-
lib/propelom/om/BaseUserCredential.php (modified) (6 diffs)
-
lib/propelom/om/BaseUserCredentialPeer.php (modified) (10 diffs)
-
lib/propelom/om/BaseUserCredentialQuery.php (modified) (19 diffs)
-
lib/propelom/om/BaseUserPeer.php (modified) (10 diffs)
-
lib/propelom/om/BaseUserQuery.php (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/Credentials/app/config/classmap-syscpng-conf.php
r48 r59 1 1 <?php 2 // This file generated by Propel 1.6. 1convert-conf target2 // This file generated by Propel 1.6.3 convert-conf target 3 3 return array ( 4 4 'BaseCredential' => 'propelom/om/BaseCredential.php', -
branches/Credentials/app/config/syscpng-conf.php
r48 r59 1 1 <?php 2 // This file generated by Propel 1.6. 1convert-conf target2 // This file generated by Propel 1.6.3 convert-conf target 3 3 // from XML runtime conf file /Users/benjamin/Workspaces/Projekte/SysCP-ng/dev/lib/propel/runtime-conf.xml 4 4 $conf = array ( … … 18 18 'default' => 'syscpng', 19 19 ), 20 'generator_version' => '1.6. 1',20 'generator_version' => '1.6.3', 21 21 ); 22 22 $conf['classmap'] = include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classmap-syscpng-conf.php'); -
branches/Credentials/app/lib/propelom/map/CredentialTableMap.php
r48 r59 50 50 public function buildRelations() 51 51 { 52 $this->addRelation('RoleCredential', 'RoleCredential', RelationMap::ONE_TO_MANY, array('id' => 'credential_id', ), null, null );53 $this->addRelation('UserCredential', 'UserCredential', RelationMap::ONE_TO_MANY, array('id' => 'credential_id', ), null, null );54 $this->addRelation('Role', 'Role', RelationMap::MANY_TO_MANY, array(), null, null );55 $this->addRelation('User', 'User', RelationMap::MANY_TO_MANY, array(), null, null );52 $this->addRelation('RoleCredential', 'RoleCredential', RelationMap::ONE_TO_MANY, array('id' => 'credential_id', ), null, null, 'RoleCredentials'); 53 $this->addRelation('UserCredential', 'UserCredential', RelationMap::ONE_TO_MANY, array('id' => 'credential_id', ), null, null, 'UserCredentials'); 54 $this->addRelation('Role', 'Role', RelationMap::MANY_TO_MANY, array(), null, null, 'Roles'); 55 $this->addRelation('User', 'User', RelationMap::MANY_TO_MANY, array(), null, null, 'Users'); 56 56 } // buildRelations() 57 57 -
branches/Credentials/app/lib/propelom/map/RoleTableMap.php
r48 r59 49 49 public function buildRelations() 50 50 { 51 $this->addRelation('User', 'User', RelationMap::ONE_TO_MANY, array('id' => 'role_id', ), null, null );52 $this->addRelation('RoleCredential', 'RoleCredential', RelationMap::ONE_TO_MANY, array('id' => 'role_id', ), null, null );53 $this->addRelation('Credential', 'Credential', RelationMap::MANY_TO_MANY, array(), null, null );51 $this->addRelation('User', 'User', RelationMap::ONE_TO_MANY, array('id' => 'role_id', ), null, null, 'Users'); 52 $this->addRelation('RoleCredential', 'RoleCredential', RelationMap::ONE_TO_MANY, array('id' => 'role_id', ), null, null, 'RoleCredentials'); 53 $this->addRelation('Credential', 'Credential', RelationMap::MANY_TO_MANY, array(), null, null, 'Credentials'); 54 54 } // buildRelations() 55 55 -
branches/Credentials/app/lib/propelom/map/UserTableMap.php
r48 r59 59 59 { 60 60 $this->addRelation('Role', 'Role', RelationMap::MANY_TO_ONE, array('role_id' => 'id', ), null, null); 61 $this->addRelation('UserCredential', 'UserCredential', RelationMap::ONE_TO_MANY, array('id' => 'user_id', ), null, null );62 $this->addRelation('Credential', 'Credential', RelationMap::MANY_TO_MANY, array(), null, null );61 $this->addRelation('UserCredential', 'UserCredential', RelationMap::ONE_TO_MANY, array('id' => 'user_id', ), null, null, 'UserCredentials'); 62 $this->addRelation('Credential', 'Credential', RelationMap::MANY_TO_MANY, array(), null, null, 'Credentials'); 63 63 } // buildRelations() 64 64 65 65 /** 66 * 66 * 67 67 * Gets the list of behaviors registered for this table 68 * 68 * 69 69 * @return array Associative array (name => parameters) of behaviors 70 70 */ -
branches/Credentials/app/lib/propelom/om/BaseCredential.php
r48 r59 78 78 79 79 /** 80 * An array of objects scheduled for deletion. 81 * @var array 82 */ 83 protected $rolesScheduledForDeletion = null; 84 85 /** 86 * An array of objects scheduled for deletion. 87 * @var array 88 */ 89 protected $usersScheduledForDeletion = null; 90 91 /** 92 * An array of objects scheduled for deletion. 93 * @var array 94 */ 95 protected $roleCredentialsScheduledForDeletion = null; 96 97 /** 98 * An array of objects scheduled for deletion. 99 * @var array 100 */ 101 protected $userCredentialsScheduledForDeletion = null; 102 103 /** 80 104 * Get the [id] column value. 81 105 * … … 302 326 $con->beginTransaction(); 303 327 try { 328 $deleteQuery = CredentialQuery::create() 329 ->filterByPrimaryKey($this->getPrimaryKey()); 304 330 $ret = $this->preDelete($con); 305 331 if ($ret) { 306 CredentialQuery::create() 307 ->filterByPrimaryKey($this->getPrimaryKey()) 308 ->delete($con); 332 $deleteQuery->delete($con); 309 333 $this->postDelete($con); 310 334 $con->commit(); … … 313 337 $con->commit(); 314 338 } 315 } catch ( PropelException $e) {339 } catch (Exception $e) { 316 340 $con->rollBack(); 317 341 throw $e; … … 365 389 $con->commit(); 366 390 return $affectedRows; 367 } catch ( PropelException $e) {391 } catch (Exception $e) { 368 392 $con->rollBack(); 369 393 throw $e; … … 388 412 $this->alreadyInSave = true; 389 413 390 if ($this->isNew() ) { 391 $this->modifiedColumns[] = CredentialPeer::ID; 392 } 393 394 // If this object has been modified, then save it to the database. 395 if ($this->isModified()) { 414 if ($this->isNew() || $this->isModified()) { 415 // persist changes 396 416 if ($this->isNew()) { 397 $criteria = $this->buildCriteria(); 398 if ($criteria->keyContainsValue(CredentialPeer::ID) ) { 399 throw new PropelException('Cannot insert a value for auto-increment primary key ('.CredentialPeer::ID.')'); 417 $this->doInsert($con); 418 } else { 419 $this->doUpdate($con); 420 } 421 $affectedRows += 1; 422 $this->resetModified(); 423 } 424 425 if ($this->rolesScheduledForDeletion !== null) { 426 if (!$this->rolesScheduledForDeletion->isEmpty()) { 427 RoleCredentialQuery::create() 428 ->filterByPrimaryKeys($this->rolesScheduledForDeletion->getPrimaryKeys(false)) 429 ->delete($con); 430 $this->rolesScheduledForDeletion = null; 431 } 432 433 foreach ($this->getRoles() as $role) { 434 if ($role->isModified()) { 435 $role->save($con); 400 436 } 401 402 $pk = BasePeer::doInsert($criteria, $con); 403 $affectedRows = 1; 404 $this->setId($pk); //[IMV] update autoincrement primary key 405 $this->setNew(false); 406 } else { 407 $affectedRows = CredentialPeer::doUpdate($this, $con); 408 } 409 410 $this->resetModified(); // [HL] After being saved an object is no longer 'modified' 437 } 438 } 439 440 if ($this->usersScheduledForDeletion !== null) { 441 if (!$this->usersScheduledForDeletion->isEmpty()) { 442 UserCredentialQuery::create() 443 ->filterByPrimaryKeys($this->usersScheduledForDeletion->getPrimaryKeys(false)) 444 ->delete($con); 445 $this->usersScheduledForDeletion = null; 446 } 447 448 foreach ($this->getUsers() as $user) { 449 if ($user->isModified()) { 450 $user->save($con); 451 } 452 } 453 } 454 455 if ($this->roleCredentialsScheduledForDeletion !== null) { 456 if (!$this->roleCredentialsScheduledForDeletion->isEmpty()) { 457 RoleCredentialQuery::create() 458 ->filterByPrimaryKeys($this->roleCredentialsScheduledForDeletion->getPrimaryKeys(false)) 459 ->delete($con); 460 $this->roleCredentialsScheduledForDeletion = null; 461 } 411 462 } 412 463 … … 419 470 } 420 471 472 if ($this->userCredentialsScheduledForDeletion !== null) { 473 if (!$this->userCredentialsScheduledForDeletion->isEmpty()) { 474 UserCredentialQuery::create() 475 ->filterByPrimaryKeys($this->userCredentialsScheduledForDeletion->getPrimaryKeys(false)) 476 ->delete($con); 477 $this->userCredentialsScheduledForDeletion = null; 478 } 479 } 480 421 481 if ($this->collUserCredentials !== null) { 422 482 foreach ($this->collUserCredentials as $referrerFK) { … … 432 492 return $affectedRows; 433 493 } // doSave() 494 495 /** 496 * Insert the row in the database. 497 * 498 * @param PropelPDO $con 499 * 500 * @throws PropelException 501 * @see doSave() 502 */ 503 protected function doInsert(PropelPDO $con) 504 { 505 $modifiedColumns = array(); 506 $index = 0; 507 508 $this->modifiedColumns[] = CredentialPeer::ID; 509 if (null !== $this->id) { 510 throw new PropelException('Cannot insert a value for auto-increment primary key (' . CredentialPeer::ID . ')'); 511 } 512 513 // check the columns in natural order for more readable SQL queries 514 if ($this->isColumnModified(CredentialPeer::ID)) { 515 $modifiedColumns[':p' . $index++] = '`ID`'; 516 } 517 if ($this->isColumnModified(CredentialPeer::MODULE)) { 518 $modifiedColumns[':p' . $index++] = '`MODULE`'; 519 } 520 if ($this->isColumnModified(CredentialPeer::VALUE)) { 521 $modifiedColumns[':p' . $index++] = '`VALUE`'; 522 } 523 524 $sql = sprintf( 525 'INSERT INTO `credential` (%s) VALUES (%s)', 526 implode(', ', $modifiedColumns), 527 implode(', ', array_keys($modifiedColumns)) 528 ); 529 530 try { 531 $stmt = $con->prepare($sql); 532 foreach ($modifiedColumns as $identifier => $columnName) { 533 switch ($columnName) { 534 case '`ID`': 535 $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); 536 break; 537 case '`MODULE`': 538 $stmt->bindValue($identifier, $this->module, PDO::PARAM_STR); 539 break; 540 case '`VALUE`': 541 $stmt->bindValue($identifier, $this->value, PDO::PARAM_STR); 542 break; 543 } 544 } 545 $stmt->execute(); 546 } catch (Exception $e) { 547 Propel::log($e->getMessage(), Propel::LOG_ERR); 548 throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e); 549 } 550 551 try { 552 $pk = $con->lastInsertId(); 553 } catch (Exception $e) { 554 throw new PropelException('Unable to get autoincrement id.', $e); 555 } 556 $this->setId($pk); 557 558 $this->setNew(false); 559 } 560 561 /** 562 * Update the row in the database. 563 * 564 * @param PropelPDO $con 565 * 566 * @see doSave() 567 */ 568 protected function doUpdate(PropelPDO $con) 569 { 570 $selectCriteria = $this->buildPkeyCriteria(); 571 $valuesCriteria = $this->buildCriteria(); 572 BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con); 573 } 434 574 435 575 /** … … 808 948 /** 809 949 * Initializes a collection based on the name of a relation. 810 * Avoids crafting an 'init[$relationName]s' method name 950 * Avoids crafting an 'init[$relationName]s' method name 811 951 * that wouldn't work when StandardEnglishPluralizer is used. 812 952 * … … 893 1033 894 1034 /** 1035 * Sets a collection of RoleCredential objects related by a one-to-many relationship 1036 * to the current object. 1037 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 1038 * and new objects from the given Propel collection. 1039 * 1040 * @param PropelCollection $roleCredentials A Propel collection. 1041 * @param PropelPDO $con Optional connection object 1042 */ 1043 public function setRoleCredentials(PropelCollection $roleCredentials, PropelPDO $con = null) 1044 { 1045 $this->roleCredentialsScheduledForDeletion = $this->getRoleCredentials(new Criteria(), $con)->diff($roleCredentials); 1046 1047 foreach ($roleCredentials as $roleCredential) { 1048 // Fix issue with collection modified by reference 1049 if ($roleCredential->isNew()) { 1050 $roleCredential->setCredential($this); 1051 } 1052 $this->addRoleCredential($roleCredential); 1053 } 1054 1055 $this->collRoleCredentials = $roleCredentials; 1056 } 1057 1058 /** 895 1059 * Returns the number of related RoleCredential objects. 896 1060 * … … 925 1089 * 926 1090 * @param RoleCredential $l RoleCredential 927 * @return void 928 * @throws PropelException 1091 * @return Credential The current object (for fluent API support) 929 1092 */ 930 1093 public function addRoleCredential(RoleCredential $l) … … 934 1097 } 935 1098 if (!$this->collRoleCredentials->contains($l)) { // only add it if the **same** object is not already associated 936 $this->collRoleCredentials[]= $l; 937 $l->setCredential($this); 938 } 1099 $this->doAddRoleCredential($l); 1100 } 1101 1102 return $this; 1103 } 1104 1105 /** 1106 * @param RoleCredential $roleCredential The roleCredential object to add. 1107 */ 1108 protected function doAddRoleCredential($roleCredential) 1109 { 1110 $this->collRoleCredentials[]= $roleCredential; 1111 $roleCredential->setCredential($this); 939 1112 } 940 1113 … … 1033 1206 1034 1207 /** 1208 * Sets a collection of UserCredential objects related by a one-to-many relationship 1209 * to the current object. 1210 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 1211 * and new objects from the given Propel collection. 1212 * 1213 * @param PropelCollection $userCredentials A Propel collection. 1214 * @param PropelPDO $con Optional connection object 1215 */ 1216 public function setUserCredentials(PropelCollection $userCredentials, PropelPDO $con = null) 1217 { 1218 $this->userCredentialsScheduledForDeletion = $this->getUserCredentials(new Criteria(), $con)->diff($userCredentials); 1219 1220 foreach ($userCredentials as $userCredential) { 1221 // Fix issue with collection modified by reference 1222 if ($userCredential->isNew()) { 1223 $userCredential->setCredential($this); 1224 } 1225 $this->addUserCredential($userCredential); 1226 } 1227 1228 $this->collUserCredentials = $userCredentials; 1229 } 1230 1231 /** 1035 1232 * Returns the number of related UserCredential objects. 1036 1233 * … … 1065 1262 * 1066 1263 * @param UserCredential $l UserCredential 1067 * @return void 1068 * @throws PropelException 1264 * @return Credential The current object (for fluent API support) 1069 1265 */ 1070 1266 public function addUserCredential(UserCredential $l) … … 1074 1270 } 1075 1271 if (!$this->collUserCredentials->contains($l)) { // only add it if the **same** object is not already associated 1076 $this->collUserCredentials[]= $l; 1077 $l->setCredential($this); 1078 } 1272 $this->doAddUserCredential($l); 1273 } 1274 1275 return $this; 1276 } 1277 1278 /** 1279 * @param UserCredential $userCredential The userCredential object to add. 1280 */ 1281 protected function doAddUserCredential($userCredential) 1282 { 1283 $this->collUserCredentials[]= $userCredential; 1284 $userCredential->setCredential($this); 1079 1285 } 1080 1286 … … 1168 1374 1169 1375 /** 1376 * Sets a collection of Role objects related by a many-to-many relationship 1377 * to the current object by way of the role_credential cross-reference table. 1378 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 1379 * and new objects from the given Propel collection. 1380 * 1381 * @param PropelCollection $roles A Propel collection. 1382 * @param PropelPDO $con Optional connection object 1383 */ 1384 public function setRoles(PropelCollection $roles, PropelPDO $con = null) 1385 { 1386 $roleCredentials = RoleCredentialQuery::create() 1387 ->filterByRole($roles) 1388 ->filterByCredential($this) 1389 ->find($con); 1390 1391 $this->rolesScheduledForDeletion = $this->getRoleCredentials()->diff($roleCredentials); 1392 $this->collRoleCredentials = $roleCredentials; 1393 1394 foreach ($roles as $role) { 1395 // Fix issue with collection modified by reference 1396 if ($role->isNew()) { 1397 $this->doAddRole($role); 1398 } else { 1399 $this->addRole($role); 1400 } 1401 } 1402 1403 $this->collRoles = $roles; 1404 } 1405 1406 /** 1170 1407 * Gets the number of Role objects related by a many-to-many relationship 1171 1408 * to the current object by way of the role_credential cross-reference table. … … 1209 1446 } 1210 1447 if (!$this->collRoles->contains($role)) { // only add it if the **same** object is not already associated 1211 $roleCredential = new RoleCredential(); 1212 $roleCredential->setRole($role); 1213 $this->addRoleCredential($roleCredential); 1448 $this->doAddRole($role); 1214 1449 1215 1450 $this->collRoles[]= $role; 1216 1451 } 1452 } 1453 1454 /** 1455 * @param Role $role The role object to add. 1456 */ 1457 protected function doAddRole($role) 1458 { 1459 $roleCredential = new RoleCredential(); 1460 $roleCredential->setRole($role); 1461 $this->addRoleCredential($roleCredential); 1217 1462 } 1218 1463 … … 1281 1526 1282 1527 /** 1528 * Sets a collection of User objects related by a many-to-many relationship 1529 * to the current object by way of the user_credential cross-reference table. 1530 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 1531 * and new objects from the given Propel collection. 1532 * 1533 * @param PropelCollection $users A Propel collection. 1534 * @param PropelPDO $con Optional connection object 1535 */ 1536 public function setUsers(PropelCollection $users, PropelPDO $con = null) 1537 { 1538 $userCredentials = UserCredentialQuery::create() 1539 ->filterByUser($users) 1540 ->filterByCredential($this) 1541 ->find($con); 1542 1543 $this->usersScheduledForDeletion = $this->getUserCredentials()->diff($userCredentials); 1544 $this->collUserCredentials = $userCredentials; 1545 1546 foreach ($users as $user) { 1547 // Fix issue with collection modified by reference 1548 if ($user->isNew()) { 1549 $this->doAddUser($user); 1550 } else { 1551 $this->addUser($user); 1552 } 1553 } 1554 1555 $this->collUsers = $users; 1556 } 1557 1558 /** 1283 1559 * Gets the number of User objects related by a many-to-many relationship 1284 1560 * to the current object by way of the user_credential cross-reference table. … … 1322 1598 } 1323 1599 if (!$this->collUsers->contains($user)) { // only add it if the **same** object is not already associated 1324 $userCredential = new UserCredential(); 1325 $userCredential->setUser($user); 1326 $this->addUserCredential($userCredential); 1600 $this->doAddUser($user); 1327 1601 1328 1602 $this->collUsers[]= $user; 1329 1603 } 1604 } 1605 1606 /** 1607 * @param User $user The user object to add. 1608 */ 1609 protected function doAddUser($user) 1610 { 1611 $userCredential = new UserCredential(); 1612 $userCredential->setUser($user); 1613 $this->addUserCredential($userCredential); 1330 1614 } 1331 1615 … … 1408 1692 } 1409 1693 1410 /**1411 * Catches calls to virtual methods1412 */1413 public function __call($name, $params)1414 {1415 if (preg_match('/get(\w+)/', $name, $matches)) {1416 $virtualColumn = $matches[1];1417 if ($this->hasVirtualColumn($virtualColumn)) {1418 return $this->getVirtualColumn($virtualColumn);1419 }1420 // no lcfirst in php<5.3...1421 $virtualColumn[0] = strtolower($virtualColumn[0]);1422 if ($this->hasVirtualColumn($virtualColumn)) {1423 return $this->getVirtualColumn($virtualColumn);1424 }1425 }1426 return parent::__call($name, $params);1427 }1428 1429 1694 } // BaseCredential -
branches/Credentials/app/lib/propelom/om/BaseCredentialPeer.php
r48 r59 25 25 /** the related TableMap class for this table */ 26 26 const TM_CLASS = 'CredentialTableMap'; 27 27 28 28 /** The total number of columns. */ 29 29 const NUM_COLUMNS = 3; … … 46 46 /** The default string format for model objects of the related table **/ 47 47 const DEFAULT_STRING_FORMAT = 'YAML'; 48 48 49 49 /** 50 50 * An identiy map to hold any loaded instances of Credential objects. … … 377 377 378 378 /** 379 * Retrieves the primary key from the DB resultset row 379 * Retrieves the primary key from the DB resultset row 380 380 * For tables with a single-column primary key, that simple pkey value will be returned. For tables with 381 381 * a multi-column primary key, an array of the primary key columns will be returned. -
branches/Credentials/app/lib/propelom/om/BaseCredentialQuery.php
r48 r59 42 42 abstract class BaseCredentialQuery extends ModelCriteria 43 43 { 44 44 45 45 /** 46 46 * Initializes internal state of BaseCredentialQuery object. … … 79 79 80 80 /** 81 * Find object by primary key 82 * Use instance pooling to avoid a database query if the object exists 81 * Find object by primary key. 82 * Propel uses the instance pool to skip the database if the object exists. 83 * Go fast if the query is untouched. 84 * 83 85 * <code> 84 86 * $obj = $c->findPk(12, $con); 85 87 * </code> 88 * 86 89 * @param mixed $key Primary key to use for the query 87 90 * @param PropelPDO $con an optional connection object … … 91 94 public function findPk($key, $con = null) 92 95 { 93 if ((null !== ($obj = CredentialPeer::getInstanceFromPool((string) $key))) && $this->getFormatter()->isObjectFormatter()) { 96 if ($key === null) { 97 return null; 98 } 99 if ((null !== ($obj = CredentialPeer::getInstanceFromPool((string) $key))) && !$this->formatter) { 94 100 // the object is alredy in the instance pool 95 101 return $obj; 102 } 103 if ($con === null) { 104 $con = Propel::getConnection(CredentialPeer::DATABASE_NAME, Propel::CONNECTION_READ); 105 } 106 $this->basePreSelect($con); 107 if ($this->formatter || $this->modelAlias || $this->with || $this->select 108 || $this->selectColumns || $this->asColumns || $this->selectModifiers 109 || $this->map || $this->having || $this->joins) { 110 return $this->findPkComplex($key, $con); 96 111 } else { 97 // the object has not been requested yet, or the formatter is not an object formatter 98 $criteria = $this->isKeepQuery() ? clone $this : $this; 99 $stmt = $criteria 100 ->filterByPrimaryKey($key) 101 ->getSelectStatement($con); 102 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 103 } 112 return $this->findPkSimple($key, $con); 113 } 114 } 115 116 /** 117 * Find object by primary key using raw SQL to go fast. 118 * Bypass doSelect() and the object formatter by using generated code. 119 * 120 * @param mixed $key Primary key to use for the query 121 * @param PropelPDO $con A connection object 122 * 123 * @return Credential A model object, or null if the key is not found 124 */ 125 protected function findPkSimple($key, $con) 126 { 127 $sql = 'SELECT `ID`, `MODULE`, `VALUE` FROM `credential` WHERE `ID` = :p0'; 128 try { 129 $stmt = $con->prepare($sql); 130 $stmt->bindValue(':p0', $key, PDO::PARAM_INT); 131 $stmt->execute(); 132 } catch (Exception $e) { 133 Propel::log($e->getMessage(), Propel::LOG_ERR); 134 throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); 135 } 136 $obj = null; 137 if ($row = $stmt->fetch(PDO::FETCH_NUM)) { 138 $obj = new Credential(); 139 $obj->hydrate($row); 140 CredentialPeer::addInstanceToPool($obj, (string) $row[0]); 141 } 142 $stmt->closeCursor(); 143 144 return $obj; 145 } 146 147 /** 148 * Find object by primary key. 149 * 150 * @param mixed $key Primary key to use for the query 151 * @param PropelPDO $con A connection object 152 * 153 * @return Credential|array|mixed the result, formatted by the current formatter 154 */ 155 protected function findPkComplex($key, $con) 156 { 157 // As the query uses a PK condition, no limit(1) is necessary. 158 $criteria = $this->isKeepQuery() ? clone $this : $this; 159 $stmt = $criteria 160 ->filterByPrimaryKey($key) 161 ->doSelect($con); 162 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 104 163 } 105 164 … … 116 175 public function findPks($keys, $con = null) 117 176 { 177 if ($con === null) { 178 $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ); 179 } 180 $this->basePreSelect($con); 118 181 $criteria = $this->isKeepQuery() ? clone $this : $this; 119 return $this182 $stmt = $criteria 120 183 ->filterByPrimaryKeys($keys) 121 ->find($con); 184 ->doSelect($con); 185 return $criteria->getFormatter()->init($criteria)->format($stmt); 122 186 } 123 187 … … 148 212 /** 149 213 * Filter the query on the id column 150 * 214 * 151 215 * Example usage: 152 216 * <code> … … 174 238 /** 175 239 * Filter the query on the module column 176 * 240 * 177 241 * Example usage: 178 242 * <code> … … 202 266 /** 203 267 * Filter the query on the value column 204 * 268 * 205 269 * Example usage: 206 270 * <code> … … 244 308 return $this 245 309 ->useRoleCredentialQuery() 246 ->filterByPrimaryKeys($roleCredential->getPrimaryKeys())310 ->filterByPrimaryKeys($roleCredential->getPrimaryKeys()) 247 311 ->endUse(); 248 312 } else { … … 253 317 /** 254 318 * Adds a JOIN clause to the query using the RoleCredential relation 255 * 319 * 256 320 * @param string $relationAlias optional alias for the relation 257 321 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 263 327 $tableMap = $this->getTableMap(); 264 328 $relationMap = $tableMap->getRelation('RoleCredential'); 265 329 266 330 // create a ModelJoin object for this join 267 331 $join = new ModelJoin(); … … 271 335 $join->setPreviousJoin($previousJoin); 272 336 } 273 337 274 338 // add the ModelJoin to the current object 275 339 if($relationAlias) { … … 279 343 $this->addJoinObject($join, 'RoleCredential'); 280 344 } 281 345 282 346 return $this; 283 347 } … … 287 351 * 288 352 * @see useQuery() 289 * 353 * 290 354 * @param string $relationAlias optional alias for the relation, 291 355 * to be used as main alias in the secondary query … … 317 381 return $this 318 382 ->useUserCredentialQuery() 319 ->filterByPrimaryKeys($userCredential->getPrimaryKeys())383 ->filterByPrimaryKeys($userCredential->getPrimaryKeys()) 320 384 ->endUse(); 321 385 } else { … … 326 390 /** 327 391 * Adds a JOIN clause to the query using the UserCredential relation 328 * 392 * 329 393 * @param string $relationAlias optional alias for the relation 330 394 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 336 400 $tableMap = $this->getTableMap(); 337 401 $relationMap = $tableMap->getRelation('UserCredential'); 338 402 339 403 // create a ModelJoin object for this join 340 404 $join = new ModelJoin(); … … 344 408 $join->setPreviousJoin($previousJoin); 345 409 } 346 410 347 411 // add the ModelJoin to the current object 348 412 if($relationAlias) { … … 352 416 $this->addJoinObject($join, 'UserCredential'); 353 417 } 354 418 355 419 return $this; 356 420 } … … 360 424 * 361 425 * @see useQuery() 362 * 426 * 363 427 * @param string $relationAlias optional alias for the relation, 364 428 * to be used as main alias in the secondary query … … 387 451 return $this 388 452 ->useRoleCredentialQuery() 389 ->filterByRole($role, $comparison)453 ->filterByRole($role, $comparison) 390 454 ->endUse(); 391 455 } 392 456 393 457 /** 394 458 * Filter the query by a related User object … … 404 468 return $this 405 469 ->useUserCredentialQuery() 406 ->filterByUser($user, $comparison)470 ->filterByUser($user, $comparison) 407 471 ->endUse(); 408 472 } 409 473 410 474 /** 411 475 * Exclude object from result … … 419 483 if ($credential) { 420 484 $this->addUsingAlias(CredentialPeer::ID, $credential->getId(), Criteria::NOT_EQUAL); 421 }422 485 } 486 423 487 return $this; 424 488 } -
branches/Credentials/app/lib/propelom/om/BaseRole.php
r48 r59 67 67 68 68 /** 69 * An array of objects scheduled for deletion. 70 * @var array 71 */ 72 protected $credentialsScheduledForDeletion = null; 73 74 /** 75 * An array of objects scheduled for deletion. 76 * @var array 77 */ 78 protected $usersScheduledForDeletion = null; 79 80 /** 81 * An array of objects scheduled for deletion. 82 * @var array 83 */ 84 protected $roleCredentialsScheduledForDeletion = null; 85 86 /** 69 87 * Get the [id] column value. 70 88 * … … 259 277 $con->beginTransaction(); 260 278 try { 279 $deleteQuery = RoleQuery::create() 280 ->filterByPrimaryKey($this->getPrimaryKey()); 261 281 $ret = $this->preDelete($con); 262 282 if ($ret) { 263 RoleQuery::create() 264 ->filterByPrimaryKey($this->getPrimaryKey()) 265 ->delete($con); 283 $deleteQuery->delete($con); 266 284 $this->postDelete($con); 267 285 $con->commit(); … … 270 288 $con->commit(); 271 289 } 272 } catch ( PropelException $e) {290 } catch (Exception $e) { 273 291 $con->rollBack(); 274 292 throw $e; … … 322 340 $con->commit(); 323 341 return $affectedRows; 324 } catch ( PropelException $e) {342 } catch (Exception $e) { 325 343 $con->rollBack(); 326 344 throw $e; … … 345 363 $this->alreadyInSave = true; 346 364 347 if ($this->isNew() ) { 348 $this->modifiedColumns[] = RolePeer::ID; 349 } 350 351 // If this object has been modified, then save it to the database. 352 if ($this->isModified()) { 365 if ($this->isNew() || $this->isModified()) { 366 // persist changes 353 367 if ($this->isNew()) { 354 $criteria = $this->buildCriteria(); 355 if ($criteria->keyContainsValue(RolePeer::ID) ) { 356 throw new PropelException('Cannot insert a value for auto-increment primary key ('.RolePeer::ID.')'); 368 $this->doInsert($con); 369 } else { 370 $this->doUpdate($con); 371 } 372 $affectedRows += 1; 373 $this->resetModified(); 374 } 375 376 if ($this->credentialsScheduledForDeletion !== null) { 377 if (!$this->credentialsScheduledForDeletion->isEmpty()) { 378 RoleCredentialQuery::create() 379 ->filterByPrimaryKeys($this->credentialsScheduledForDeletion->getPrimaryKeys(false)) 380 ->delete($con); 381 $this->credentialsScheduledForDeletion = null; 382 } 383 384 foreach ($this->getCredentials() as $credential) { 385 if ($credential->isModified()) { 386 $credential->save($con); 357 387 } 358 359 $pk = BasePeer::doInsert($criteria, $con);360 $affectedRows = 1; 361 $this->setId($pk); //[IMV] update autoincrement primary key362 $this->setNew(false);363 } else {364 $affectedRows = RolePeer::doUpdate($this, $con);365 }366 367 $this->resetModified(); // [HL] After being saved an object is no longer 'modified'388 } 389 } 390 391 if ($this->usersScheduledForDeletion !== null) { 392 if (!$this->usersScheduledForDeletion->isEmpty()) { 393 UserQuery::create() 394 ->filterByPrimaryKeys($this->usersScheduledForDeletion->getPrimaryKeys(false)) 395 ->delete($con); 396 $this->usersScheduledForDeletion = null; 397 } 368 398 } 369 399 … … 376 406 } 377 407 408 if ($this->roleCredentialsScheduledForDeletion !== null) { 409 if (!$this->roleCredentialsScheduledForDeletion->isEmpty()) { 410 RoleCredentialQuery::create() 411 ->filterByPrimaryKeys($this->roleCredentialsScheduledForDeletion->getPrimaryKeys(false)) 412 ->delete($con); 413 $this->roleCredentialsScheduledForDeletion = null; 414 } 415 } 416 378 417 if ($this->collRoleCredentials !== null) { 379 418 foreach ($this->collRoleCredentials as $referrerFK) { … … 389 428 return $affectedRows; 390 429 } // doSave() 430 431 /** 432 * Insert the row in the database. 433 * 434 * @param PropelPDO $con 435 * 436 * @throws PropelException 437 * @see doSave() 438 */ 439 protected function doInsert(PropelPDO $con) 440 { 441 $modifiedColumns = array(); 442 $index = 0; 443 444 $this->modifiedColumns[] = RolePeer::ID; 445 if (null !== $this->id) { 446 throw new PropelException('Cannot insert a value for auto-increment primary key (' . RolePeer::ID . ')'); 447 } 448 449 // check the columns in natural order for more readable SQL queries 450 if ($this->isColumnModified(RolePeer::ID)) { 451 $modifiedColumns[':p' . $index++] = '`ID`'; 452 } 453 if ($this->isColumnModified(RolePeer::ROLENAME)) { 454 $modifiedColumns[':p' . $index++] = '`ROLENAME`'; 455 } 456 457 $sql = sprintf( 458 'INSERT INTO `role` (%s) VALUES (%s)', 459 implode(', ', $modifiedColumns), 460 implode(', ', array_keys($modifiedColumns)) 461 ); 462 463 try { 464 $stmt = $con->prepare($sql); 465 foreach ($modifiedColumns as $identifier => $columnName) { 466 switch ($columnName) { 467 case '`ID`': 468 $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); 469 break; 470 case '`ROLENAME`': 471 $stmt->bindValue($identifier, $this->rolename, PDO::PARAM_STR); 472 break; 473 } 474 } 475 $stmt->execute(); 476 } catch (Exception $e) { 477 Propel::log($e->getMessage(), Propel::LOG_ERR); 478 throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e); 479 } 480 481 try { 482 $pk = $con->lastInsertId(); 483 } catch (Exception $e) { 484 throw new PropelException('Unable to get autoincrement id.', $e); 485 } 486 $this->setId($pk); 487 488 $this->setNew(false); 489 } 490 491 /** 492 * Update the row in the database. 493 * 494 * @param PropelPDO $con 495 * 496 * @see doSave() 497 */ 498 protected function doUpdate(PropelPDO $con) 499 { 500 $selectCriteria = $this->buildPkeyCriteria(); 501 $valuesCriteria = $this->buildCriteria(); 502 BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con); 503 } 391 504 392 505 /** … … 755 868 /** 756 869 * Initializes a collection based on the name of a relation. 757 * Avoids crafting an 'init[$relationName]s' method name 870 * Avoids crafting an 'init[$relationName]s' method name 758 871 * that wouldn't work when StandardEnglishPluralizer is used. 759 872 * … … 840 953 841 954 /** 955 * Sets a collection of User objects related by a one-to-many relationship 956 * to the current object. 957 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 958 * and new objects from the given Propel collection. 959 * 960 * @param PropelCollection $users A Propel collection. 961 * @param PropelPDO $con Optional connection object 962 */ 963 public function setUsers(PropelCollection $users, PropelPDO $con = null) 964 { 965 $this->usersScheduledForDeletion = $this->getUsers(new Criteria(), $con)->diff($users); 966 967 foreach ($users as $user) { 968 // Fix issue with collection modified by reference 969 if ($user->isNew()) { 970 $user->setRole($this); 971 } 972 $this->addUser($user); 973 } 974 975 $this->collUsers = $users; 976 } 977 978 /** 842 979 * Returns the number of related User objects. 843 980 * … … 872 1009 * 873 1010 * @param User $l User 874 * @return void 875 * @throws PropelException 1011 * @return Role The current object (for fluent API support) 876 1012 */ 877 1013 public function addUser(User $l) … … 881 1017 } 882 1018 if (!$this->collUsers->contains($l)) { // only add it if the **same** object is not already associated 883 $this->collUsers[]= $l; 884 $l->setRole($this); 885 } 1019 $this->doAddUser($l); 1020 } 1021 1022 return $this; 1023 } 1024 1025 /** 1026 * @param User $user The user object to add. 1027 */ 1028 protected function doAddUser($user) 1029 { 1030 $this->collUsers[]= $user; 1031 $user->setRole($this); 886 1032 } 887 1033 … … 955 1101 956 1102 /** 1103 * Sets a collection of RoleCredential objects related by a one-to-many relationship 1104 * to the current object. 1105 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 1106 * and new objects from the given Propel collection. 1107 * 1108 * @param PropelCollection $roleCredentials A Propel collection. 1109 * @param PropelPDO $con Optional connection object 1110 */ 1111 public function setRoleCredentials(PropelCollection $roleCredentials, PropelPDO $con = null) 1112 { 1113 $this->roleCredentialsScheduledForDeletion = $this->getRoleCredentials(new Criteria(), $con)->diff($roleCredentials); 1114 1115 foreach ($roleCredentials as $roleCredential) { 1116 // Fix issue with collection modified by reference 1117 if ($roleCredential->isNew()) { 1118 $roleCredential->setRole($this); 1119 } 1120 $this->addRoleCredential($roleCredential); 1121 } 1122 1123 $this->collRoleCredentials = $roleCredentials; 1124 } 1125 1126 /** 957 1127 * Returns the number of related RoleCredential objects. 958 1128 * … … 987 1157 * 988 1158 * @param RoleCredential $l RoleCredential 989 * @return void 990 * @throws PropelException 1159 * @return Role The current object (for fluent API support) 991 1160 */ 992 1161 public function addRoleCredential(RoleCredential $l) … … 996 1165 } 997 1166 if (!$this->collRoleCredentials->contains($l)) { // only add it if the **same** object is not already associated 998 $this->collRoleCredentials[]= $l; 999 $l->setRole($this); 1000 } 1167 $this->doAddRoleCredential($l); 1168 } 1169 1170 return $this; 1171 } 1172 1173 /** 1174 * @param RoleCredential $roleCredential The roleCredential object to add. 1175 */ 1176 protected function doAddRoleCredential($roleCredential) 1177 { 1178 $this->collRoleCredentials[]= $roleCredential; 1179 $roleCredential->setRole($this); 1001 1180 } 1002 1181 … … 1090 1269 1091 1270 /** 1271 * Sets a collection of Credential objects related by a many-to-many relationship 1272 * to the current object by way of the role_credential cross-reference table. 1273 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 1274 * and new objects from the given Propel collection. 1275 * 1276 * @param PropelCollection $credentials A Propel collection. 1277 * @param PropelPDO $con Optional connection object 1278 */ 1279 public function setCredentials(PropelCollection $credentials, PropelPDO $con = null) 1280 { 1281 $roleCredentials = RoleCredentialQuery::create() 1282 ->filterByCredential($credentials) 1283 ->filterByRole($this) 1284 ->find($con); 1285 1286 $this->credentialsScheduledForDeletion = $this->getRoleCredentials()->diff($roleCredentials); 1287 $this->collRoleCredentials = $roleCredentials; 1288 1289 foreach ($credentials as $credential) { 1290 // Fix issue with collection modified by reference 1291 if ($credential->isNew()) { 1292 $this->doAddCredential($credential); 1293 } else { 1294 $this->addCredential($credential); 1295 } 1296 } 1297 1298 $this->collCredentials = $credentials; 1299 } 1300 1301 /** 1092 1302 * Gets the number of Credential objects related by a many-to-many relationship 1093 1303 * to the current object by way of the role_credential cross-reference table. … … 1131 1341 } 1132 1342 if (!$this->collCredentials->contains($credential)) { // only add it if the **same** object is not already associated 1133 $roleCredential = new RoleCredential(); 1134 $roleCredential->setCredential($credential); 1135 $this->addRoleCredential($roleCredential); 1343 $this->doAddCredential($credential); 1136 1344 1137 1345 $this->collCredentials[]= $credential; 1138 1346 } 1347 } 1348 1349 /** 1350 * @param Credential $credential The credential object to add. 1351 */ 1352 protected function doAddCredential($credential) 1353 { 1354 $roleCredential = new RoleCredential(); 1355 $roleCredential->setCredential($credential); 1356 $this->addRoleCredential($roleCredential); 1139 1357 } 1140 1358 … … 1207 1425 } 1208 1426 1209 /**1210 * Catches calls to virtual methods1211 */1212 public function __call($name, $params)1213 {1214 if (preg_match('/get(\w+)/', $name, $matches)) {1215 $virtualColumn = $matches[1];1216 if ($this->hasVirtualColumn($virtualColumn)) {1217 return $this->getVirtualColumn($virtualColumn);1218 }1219 // no lcfirst in php<5.3...1220 $virtualColumn[0] = strtolower($virtualColumn[0]);1221 if ($this->hasVirtualColumn($virtualColumn)) {1222 return $this->getVirtualColumn($virtualColumn);1223 }1224 }1225 return parent::__call($name, $params);1226 }1227 1228 1427 } // BaseRole -
branches/Credentials/app/lib/propelom/om/BaseRoleCredential.php
r48 r59 265 265 $con->beginTransaction(); 266 266 try { 267 $deleteQuery = RoleCredentialQuery::create() 268 ->filterByPrimaryKey($this->getPrimaryKey()); 267 269 $ret = $this->preDelete($con); 268 270 if ($ret) { 269 RoleCredentialQuery::create() 270 ->filterByPrimaryKey($this->getPrimaryKey()) 271 ->delete($con); 271 $deleteQuery->delete($con); 272 272 $this->postDelete($con); 273 273 $con->commit(); … … 276 276 $con->commit(); 277 277 } 278 } catch ( PropelException $e) {278 } catch (Exception $e) { 279 279 $con->rollBack(); 280 280 throw $e; … … 328 328 $con->commit(); 329 329 return $affectedRows; 330 } catch ( PropelException $e) {330 } catch (Exception $e) { 331 331 $con->rollBack(); 332 332 throw $e; … … 370 370 } 371 371 372 373 // If this object has been modified, then save it to the database. 374 if ($this->isModified()) { 372 if ($this->isNew() || $this->isModified()) { 373 // persist changes 375 374 if ($this->isNew()) { 376 $criteria = $this->buildCriteria(); 377 $pk = BasePeer::doInsert($criteria, $con); 378 $affectedRows += 1; 379 $this->setNew(false); 375 $this->doInsert($con); 380 376 } else { 381 $ affectedRows += RoleCredentialPeer::doUpdate($this,$con);377 $this->doUpdate($con); 382 378 } 383 384 $this->resetModified(); // [HL] After being saved an object is no longer 'modified'379 $affectedRows += 1; 380 $this->resetModified(); 385 381 } 386 382 … … 390 386 return $affectedRows; 391 387 } // doSave() 388 389 /** 390 * Insert the row in the database. 391 * 392 * @param PropelPDO $con 393 * 394 * @throws PropelException 395 * @see doSave() 396 */ 397 protected function doInsert(PropelPDO $con) 398 { 399 $modifiedColumns = array(); 400 $index = 0; 401 402 403 // check the columns in natural order for more readable SQL queries 404 if ($this->isColumnModified(RoleCredentialPeer::ROLE_ID)) { 405 $modifiedColumns[':p' . $index++] = '`ROLE_ID`'; 406 } 407 if ($this->isColumnModified(RoleCredentialPeer::CREDENTIAL_ID)) { 408 $modifiedColumns[':p' . $index++] = '`CREDENTIAL_ID`'; 409 } 410 411 $sql = sprintf( 412 'INSERT INTO `role_credential` (%s) VALUES (%s)', 413 implode(', ', $modifiedColumns), 414 implode(', ', array_keys($modifiedColumns)) 415 ); 416 417 try { 418 $stmt = $con->prepare($sql); 419 foreach ($modifiedColumns as $identifier => $columnName) { 420 switch ($columnName) { 421 case '`ROLE_ID`': 422 $stmt->bindValue($identifier, $this->role_id, PDO::PARAM_INT); 423 break; 424 case '`CREDENTIAL_ID`': 425 $stmt->bindValue($identifier, $this->credential_id, PDO::PARAM_INT); 426 break; 427 } 428 } 429 $stmt->execute(); 430 } catch (Exception $e) { 431 Propel::log($e->getMessage(), Propel::LOG_ERR); 432 throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e); 433 } 434 435 $this->setNew(false); 436 } 437 438 /** 439 * Update the row in the database. 440 * 441 * @param PropelPDO $con 442 * 443 * @see doSave() 444 */ 445 protected function doUpdate(PropelPDO $con) 446 { 447 $selectCriteria = $this->buildPkeyCriteria(); 448 $valuesCriteria = $this->buildCriteria(); 449 BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con); 450 } 392 451 393 452 /** … … 883 942 } 884 943 885 /**886 * Catches calls to virtual methods887 */888 public function __call($name, $params)889 {890 if (preg_match('/get(\w+)/', $name, $matches)) {891 $virtualColumn = $matches[1];892 if ($this->hasVirtualColumn($virtualColumn)) {893 return $this->getVirtualColumn($virtualColumn);894 }895 // no lcfirst in php<5.3...896 $virtualColumn[0] = strtolower($virtualColumn[0]);897 if ($this->hasVirtualColumn($virtualColumn)) {898 return $this->getVirtualColumn($virtualColumn);899 }900 }901 return parent::__call($name, $params);902 }903 904 944 } // BaseRoleCredential -
branches/Credentials/app/lib/propelom/om/BaseRoleCredentialPeer.php
r48 r59 25 25 /** the related TableMap class for this table */ 26 26 const TM_CLASS = 'RoleCredentialTableMap'; 27 27 28 28 /** The total number of columns. */ 29 29 const NUM_COLUMNS = 2; … … 43 43 /** The default string format for model objects of the related table **/ 44 44 const DEFAULT_STRING_FORMAT = 'YAML'; 45 45 46 46 /** 47 47 * An identiy map to hold any loaded instances of RoleCredential objects. … … 372 372 373 373 /** 374 * Retrieves the primary key from the DB resultset row 374 * Retrieves the primary key from the DB resultset row 375 375 * For tables with a single-column primary key, that simple pkey value will be returned. For tables with 376 376 * a multi-column primary key, an array of the primary key columns will be returned. … … 469 469 RoleCredentialPeer::addSelectColumns($criteria); 470 470 } 471 471 472 472 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count 473 473 474 474 // Set the correct dbName 475 475 $criteria->setDbName(self::DATABASE_NAME); … … 519 519 RoleCredentialPeer::addSelectColumns($criteria); 520 520 } 521 521 522 522 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count 523 523 524 524 // Set the correct dbName 525 525 $criteria->setDbName(self::DATABASE_NAME); … … 701 701 RoleCredentialPeer::addSelectColumns($criteria); 702 702 } 703 703 704 704 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count 705 705 706 706 // Set the correct dbName 707 707 $criteria->setDbName(self::DATABASE_NAME); … … 836 836 // tables go into the FROM clause. 837 837 $criteria->setPrimaryTableName(RoleCredentialPeer::TABLE_NAME); 838 838 839 839 if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { 840 840 $criteria->setDistinct(); … … 844 844 RoleCredentialPeer::addSelectColumns($criteria); 845 845 } 846 846 847 847 $criteria->clearOrderByColumns(); // ORDER BY should not affect count 848 848 849 849 // Set the correct dbName 850 850 $criteria->setDbName(self::DATABASE_NAME); … … 886 886 // tables go into the FROM clause. 887 887 $criteria->setPrimaryTableName(RoleCredentialPeer::TABLE_NAME); 888 888 889 889 if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { 890 890 $criteria->setDistinct(); … … 894 894 RoleCredentialPeer::addSelectColumns($criteria); 895 895 } 896 896 897 897 $criteria->clearOrderByColumns(); // ORDER BY should not affect count 898 898 899 899 // Set the correct dbName 900 900 $criteria->setDbName(self::DATABASE_NAME); -
branches/Credentials/app/lib/propelom/om/BaseRoleCredentialQuery.php
r48 r59 38 38 abstract class BaseRoleCredentialQuery extends ModelCriteria 39 39 { 40 40 41 41 /** 42 42 * Initializes internal state of BaseRoleCredentialQuery object. … … 75 75 76 76 /** 77 * Find object by primary key 77 * Find object by primary key. 78 * Propel uses the instance pool to skip the database if the object exists. 79 * Go fast if the query is untouched. 80 * 78 81 * <code> 79 82 * $obj = $c->findPk(array(12, 34), $con); 80 83 * </code> 84 * 81 85 * @param array[$role_id, $credential_id] $key Primary key to use for the query 82 86 * @param PropelPDO $con an optional connection object … … 86 90 public function findPk($key, $con = null) 87 91 { 88 if ((null !== ($obj = RoleCredentialPeer::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && $this->getFormatter()->isObjectFormatter()) { 92 if ($key === null) { 93 return null; 94 } 95 if ((null !== ($obj = RoleCredentialPeer::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { 89 96 // the object is alredy in the instance pool 90 97 return $obj; 98 } 99 if ($con === null) { 100 $con = Propel::getConnection(RoleCredentialPeer::DATABASE_NAME, Propel::CONNECTION_READ); 101 } 102 $this->basePreSelect($con); 103 if ($this->formatter || $this->modelAlias || $this->with || $this->select 104 || $this->selectColumns || $this->asColumns || $this->selectModifiers 105 || $this->map || $this->having || $this->joins) { 106 return $this->findPkComplex($key, $con); 91 107 } else { 92 // the object has not been requested yet, or the formatter is not an object formatter 93 $criteria = $this->isKeepQuery() ? clone $this : $this; 94 $stmt = $criteria 95 ->filterByPrimaryKey($key) 96 ->getSelectStatement($con); 97 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 98 } 108 return $this->findPkSimple($key, $con); 109 } 110 } 111 112 /** 113 * Find object by primary key using raw SQL to go fast. 114 * Bypass doSelect() and the object formatter by using generated code. 115 * 116 * @param mixed $key Primary key to use for the query 117 * @param PropelPDO $con A connection object 118 * 119 * @return RoleCredential A model object, or null if the key is not found 120 */ 121 protected function findPkSimple($key, $con) 122 { 123 $sql = 'SELECT `ROLE_ID`, `CREDENTIAL_ID` FROM `role_credential` WHERE `ROLE_ID` = :p0 AND `CREDENTIAL_ID` = :p1'; 124 try { 125 $stmt = $con->prepare($sql); 126 $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); 127 $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT); 128 $stmt->execute(); 129 } catch (Exception $e) { 130 Propel::log($e->getMessage(), Propel::LOG_ERR); 131 throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); 132 } 133 $obj = null; 134 if ($row = $stmt->fetch(PDO::FETCH_NUM)) { 135 $obj = new RoleCredential(); 136 $obj->hydrate($row); 137 RoleCredentialPeer::addInstanceToPool($obj, serialize(array((string) $row[0], (string) $row[1]))); 138 } 139 $stmt->closeCursor(); 140 141 return $obj; 142 } 143 144 /** 145 * Find object by primary key. 146 * 147 * @param mixed $key Primary key to use for the query 148 * @param PropelPDO $con A connection object 149 * 150 * @return RoleCredential|array|mixed the result, formatted by the current formatter 151 */ 152 protected function findPkComplex($key, $con) 153 { 154 // As the query uses a PK condition, no limit(1) is necessary. 155 $criteria = $this->isKeepQuery() ? clone $this : $this; 156 $stmt = $criteria 157 ->filterByPrimaryKey($key) 158 ->doSelect($con); 159 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 99 160 } 100 161 … … 111 172 public function findPks($keys, $con = null) 112 173 { 174 if ($con === null) { 175 $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ); 176 } 177 $this->basePreSelect($con); 113 178 $criteria = $this->isKeepQuery() ? clone $this : $this; 114 return $this179 $stmt = $criteria 115 180 ->filterByPrimaryKeys($keys) 116 ->find($con); 181 ->doSelect($con); 182 return $criteria->getFormatter()->init($criteria)->format($stmt); 117 183 } 118 184 … … 128 194 $this->addUsingAlias(RoleCredentialPeer::ROLE_ID, $key[0], Criteria::EQUAL); 129 195 $this->addUsingAlias(RoleCredentialPeer::CREDENTIAL_ID, $key[1], Criteria::EQUAL); 130 196 131 197 return $this; 132 198 } … … 150 216 $this->addOr($cton0); 151 217 } 152 218 153 219 return $this; 154 220 } … … 156 222 /** 157 223 * Filter the query on the role_id column 158 * 224 * 159 225 * Example usage: 160 226 * <code> … … 184 250 /** 185 251 * Filter the query on the credential_id column 186 * 252 * 187 253 * Example usage: 188 254 * <code> … … 236 302 /** 237 303 * Adds a JOIN clause to the query using the Role relation 238 * 304 * 239 305 * @param string $relationAlias optional alias for the relation 240 306 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 246 312 $tableMap = $this->getTableMap(); 247 313 $relationMap = $tableMap->getRelation('Role'); 248 314 249 315 // create a ModelJoin object for this join 250 316 $join = new ModelJoin(); … … 254 320 $join->setPreviousJoin($previousJoin); 255 321 } 256 322 257 323 // add the ModelJoin to the current object 258 324 if($relationAlias) { … … 262 328 $this->addJoinObject($join, 'Role'); 263 329 } 264 330 265 331 return $this; 266 332 } … … 270 336 * 271 337 * @see useQuery() 272 * 338 * 273 339 * @param string $relationAlias optional alias for the relation, 274 340 * to be used as main alias in the secondary query … … 310 376 /** 311 377 * Adds a JOIN clause to the query using the Credential relation 312 * 378 * 313 379 * @param string $relationAlias optional alias for the relation 314 380 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 320 386 $tableMap = $this->getTableMap(); 321 387 $relationMap = $tableMap->getRelation('Credential'); 322 388 323 389 // create a ModelJoin object for this join 324 390 $join = new ModelJoin(); … … 328 394 $join->setPreviousJoin($previousJoin); 329 395 } 330 396 331 397 // add the ModelJoin to the current object 332 398 if($relationAlias) { … … 336 402 $this->addJoinObject($join, 'Credential'); 337 403 } 338 404 339 405 return $this; 340 406 } … … 344 410 * 345 411 * @see useQuery() 346 * 412 * 347 413 * @param string $relationAlias optional alias for the relation, 348 414 * to be used as main alias in the secondary query … … 371 437 $this->addCond('pruneCond1', $this->getAliasedColName(RoleCredentialPeer::CREDENTIAL_ID), $roleCredential->getCredentialId(), Criteria::NOT_EQUAL); 372 438 $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); 373 }374 439 } 440 375 441 return $this; 376 442 } -
branches/Credentials/app/lib/propelom/om/BaseRolePeer.php
r48 r59 25 25 /** the related TableMap class for this table */ 26 26 const TM_CLASS = 'RoleTableMap'; 27 27 28 28 /** The total number of columns. */ 29 29 const NUM_COLUMNS = 2; … … 43 43 /** The default string format for model objects of the related table **/ 44 44 const DEFAULT_STRING_FORMAT = 'YAML'; 45 45 46 46 /** 47 47 * An identiy map to hold any loaded instances of Role objects. … … 372 372 373 373 /** 374 * Retrieves the primary key from the DB resultset row 374 * Retrieves the primary key from the DB resultset row 375 375 * For tables with a single-column primary key, that simple pkey value will be returned. For tables with 376 376 * a multi-column primary key, an array of the primary key columns will be returned. -
branches/Credentials/app/lib/propelom/om/BaseRoleQuery.php
r48 r59 38 38 abstract class BaseRoleQuery extends ModelCriteria 39 39 { 40 40 41 41 /** 42 42 * Initializes internal state of BaseRoleQuery object. … … 75 75 76 76 /** 77 * Find object by primary key 78 * Use instance pooling to avoid a database query if the object exists 77 * Find object by primary key. 78 * Propel uses the instance pool to skip the database if the object exists. 79 * Go fast if the query is untouched. 80 * 79 81 * <code> 80 82 * $obj = $c->findPk(12, $con); 81 83 * </code> 84 * 82 85 * @param mixed $key Primary key to use for the query 83 86 * @param PropelPDO $con an optional connection object … … 87 90 public function findPk($key, $con = null) 88 91 { 89 if ((null !== ($obj = RolePeer::getInstanceFromPool((string) $key))) && $this->getFormatter()->isObjectFormatter()) { 92 if ($key === null) { 93 return null; 94 } 95 if ((null !== ($obj = RolePeer::getInstanceFromPool((string) $key))) && !$this->formatter) { 90 96 // the object is alredy in the instance pool 91 97 return $obj; 98 } 99 if ($con === null) { 100 $con = Propel::getConnection(RolePeer::DATABASE_NAME, Propel::CONNECTION_READ); 101 } 102 $this->basePreSelect($con); 103 if ($this->formatter || $this->modelAlias || $this->with || $this->select 104 || $this->selectColumns || $this->asColumns || $this->selectModifiers 105 || $this->map || $this->having || $this->joins) { 106 return $this->findPkComplex($key, $con); 92 107 } else { 93 // the object has not been requested yet, or the formatter is not an object formatter 94 $criteria = $this->isKeepQuery() ? clone $this : $this; 95 $stmt = $criteria 96 ->filterByPrimaryKey($key) 97 ->getSelectStatement($con); 98 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 99 } 108 return $this->findPkSimple($key, $con); 109 } 110 } 111 112 /** 113 * Find object by primary key using raw SQL to go fast. 114 * Bypass doSelect() and the object formatter by using generated code. 115 * 116 * @param mixed $key Primary key to use for the query 117 * @param PropelPDO $con A connection object 118 * 119 * @return Role A model object, or null if the key is not found 120 */ 121 protected function findPkSimple($key, $con) 122 { 123 $sql = 'SELECT `ID`, `ROLENAME` FROM `role` WHERE `ID` = :p0'; 124 try { 125 $stmt = $con->prepare($sql); 126 $stmt->bindValue(':p0', $key, PDO::PARAM_INT); 127 $stmt->execute(); 128 } catch (Exception $e) { 129 Propel::log($e->getMessage(), Propel::LOG_ERR); 130 throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); 131 } 132 $obj = null; 133 if ($row = $stmt->fetch(PDO::FETCH_NUM)) { 134 $obj = new Role(); 135 $obj->hydrate($row); 136 RolePeer::addInstanceToPool($obj, (string) $row[0]); 137 } 138 $stmt->closeCursor(); 139 140 return $obj; 141 } 142 143 /** 144 * Find object by primary key. 145 * 146 * @param mixed $key Primary key to use for the query 147 * @param PropelPDO $con A connection object 148 * 149 * @return Role|array|mixed the result, formatted by the current formatter 150 */ 151 protected function findPkComplex($key, $con) 152 { 153 // As the query uses a PK condition, no limit(1) is necessary. 154 $criteria = $this->isKeepQuery() ? clone $this : $this; 155 $stmt = $criteria 156 ->filterByPrimaryKey($key) 157 ->doSelect($con); 158 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 100 159 } 101 160 … … 112 171 public function findPks($keys, $con = null) 113 172 { 173 if ($con === null) { 174 $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ); 175 } 176 $this->basePreSelect($con); 114 177 $criteria = $this->isKeepQuery() ? clone $this : $this; 115 return $this178 $stmt = $criteria 116 179 ->filterByPrimaryKeys($keys) 117 ->find($con); 180 ->doSelect($con); 181 return $criteria->getFormatter()->init($criteria)->format($stmt); 118 182 } 119 183 … … 144 208 /** 145 209 * Filter the query on the id column 146 * 210 * 147 211 * Example usage: 148 212 * <code> … … 170 234 /** 171 235 * Filter the query on the rolename column 172 * 236 * 173 237 * Example usage: 174 238 * <code> … … 212 276 return $this 213 277 ->useUserQuery() 214 ->filterByPrimaryKeys($user->getPrimaryKeys())278 ->filterByPrimaryKeys($user->getPrimaryKeys()) 215 279 ->endUse(); 216 280 } else { … … 221 285 /** 222 286 * Adds a JOIN clause to the query using the User relation 223 * 287 * 224 288 * @param string $relationAlias optional alias for the relation 225 289 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 231 295 $tableMap = $this->getTableMap(); 232 296 $relationMap = $tableMap->getRelation('User'); 233 297 234 298 // create a ModelJoin object for this join 235 299 $join = new ModelJoin(); … … 239 303 $join->setPreviousJoin($previousJoin); 240 304 } 241 305 242 306 // add the ModelJoin to the current object 243 307 if($relationAlias) { … … 247 311 $this->addJoinObject($join, 'User'); 248 312 } 249 313 250 314 return $this; 251 315 } … … 255 319 * 256 320 * @see useQuery() 257 * 321 * 258 322 * @param string $relationAlias optional alias for the relation, 259 323 * to be used as main alias in the secondary query … … 285 349 return $this 286 350 ->useRoleCredentialQuery() 287 ->filterByPrimaryKeys($roleCredential->getPrimaryKeys())351 ->filterByPrimaryKeys($roleCredential->getPrimaryKeys()) 288 352 ->endUse(); 289 353 } else { … … 294 358 /** 295 359 * Adds a JOIN clause to the query using the RoleCredential relation 296 * 360 * 297 361 * @param string $relationAlias optional alias for the relation 298 362 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 304 368 $tableMap = $this->getTableMap(); 305 369 $relationMap = $tableMap->getRelation('RoleCredential'); 306 370 307 371 // create a ModelJoin object for this join 308 372 $join = new ModelJoin(); … … 312 376 $join->setPreviousJoin($previousJoin); 313 377 } 314 378 315 379 // add the ModelJoin to the current object 316 380 if($relationAlias) { … … 320 384 $this->addJoinObject($join, 'RoleCredential'); 321 385 } 322 386 323 387 return $this; 324 388 } … … 328 392 * 329 393 * @see useQuery() 330 * 394 * 331 395 * @param string $relationAlias optional alias for the relation, 332 396 * to be used as main alias in the secondary query … … 355 419 return $this 356 420 ->useRoleCredentialQuery() 357 ->filterByCredential($credential, $comparison)421 ->filterByCredential($credential, $comparison) 358 422 ->endUse(); 359 423 } 360 424 361 425 /** 362 426 * Exclude object from result … … 370 434 if ($role) { 371 435 $this->addUsingAlias(RolePeer::ID, $role->getId(), Criteria::NOT_EQUAL); 372 }373 436 } 437 374 438 return $this; 375 439 } -
branches/Credentials/app/lib/propelom/om/BaseUser.php
r48 r59 143 143 144 144 /** 145 * An array of objects scheduled for deletion. 146 * @var array 147 */ 148 protected $credentialsScheduledForDeletion = null; 149 150 /** 151 * An array of objects scheduled for deletion. 152 * @var array 153 */ 154 protected $userCredentialsScheduledForDeletion = null; 155 156 /** 145 157 * Applies default values to this object. 146 158 * This method should be called from the object's constructor (or … … 437 449 } 438 450 439 if ($this->login_failure_count !== $v || $this->isNew()) {451 if ($this->login_failure_count !== $v) { 440 452 $this->login_failure_count = $v; 441 453 $this->modifiedColumns[] = UserPeer::LOGIN_FAILURE_COUNT; … … 675 687 $con->beginTransaction(); 676 688 try { 689 $deleteQuery = UserQuery::create() 690 ->filterByPrimaryKey($this->getPrimaryKey()); 677 691 $ret = $this->preDelete($con); 678 692 // nested_set behavior … … 686 700 687 701 if ($ret) { 688 UserQuery::create() 689 ->filterByPrimaryKey($this->getPrimaryKey()) 690 ->delete($con); 702 $deleteQuery->delete($con); 691 703 $this->postDelete($con); 692 704 // nested_set behavior … … 701 713 $con->commit(); 702 714 } 703 } catch ( PropelException $e) {715 } catch (Exception $e) { 704 716 $con->rollBack(); 705 717 throw $e; … … 764 776 $con->commit(); 765 777 return $affectedRows; 766 } catch ( PropelException $e) {778 } catch (Exception $e) { 767 779 $con->rollBack(); 768 780 throw $e; … … 799 811 } 800 812 801 if ($this->isNew() ) { 802 $this->modifiedColumns[] = UserPeer::ID; 803 } 804 805 // If this object has been modified, then save it to the database. 806 if ($this->isModified()) { 813 if ($this->isNew() || $this->isModified()) { 814 // persist changes 807 815 if ($this->isNew()) { 808 $criteria = $this->buildCriteria(); 809 if ($criteria->keyContainsValue(UserPeer::ID) ) { 810 throw new PropelException('Cannot insert a value for auto-increment primary key ('.UserPeer::ID.')'); 816 $this->doInsert($con); 817 } else { 818 $this->doUpdate($con); 819 } 820 $affectedRows += 1; 821 $this->resetModified(); 822 } 823 824 if ($this->credentialsScheduledForDeletion !== null) { 825 if (!$this->credentialsScheduledForDeletion->isEmpty()) { 826 UserCredentialQuery::create() 827 ->filterByPrimaryKeys($this->credentialsScheduledForDeletion->getPrimaryKeys(false)) 828 ->delete($con); 829 $this->credentialsScheduledForDeletion = null; 830 } 831 832 foreach ($this->getCredentials() as $credential) { 833 if ($credential->isModified()) { 834 $credential->save($con); 811 835 } 812 813 $pk = BasePeer::doInsert($criteria, $con);814 $affectedRows += 1;815 $this->setId($pk); //[IMV] update autoincrement primary key816 $this->setNew(false);817 } else {818 $affectedRows += UserPeer::doUpdate($this, $con);819 836 } 820 821 $this->resetModified(); // [HL] After being saved an object is no longer 'modified' 837 } 838 839 if ($this->userCredentialsScheduledForDeletion !== null) { 840 if (!$this->userCredentialsScheduledForDeletion->isEmpty()) { 841 UserCredentialQuery::create() 842 ->filterByPrimaryKeys($this->userCredentialsScheduledForDeletion->getPrimaryKeys(false)) 843 ->delete($con); 844 $this->userCredentialsScheduledForDeletion = null; 845 } 822 846 } 823 847 … … 835 859 return $affectedRows; 836 860 } // doSave() 861 862 /** 863 * Insert the row in the database. 864 * 865 * @param PropelPDO $con 866 * 867 * @throws PropelException 868 * @see doSave() 869 */ 870 protected function doInsert(PropelPDO $con) 871 { 872 $modifiedColumns = array(); 873 $index = 0; 874 875 $this->modifiedColumns[] = UserPeer::ID; 876 if (null !== $this->id) { 877 throw new PropelException('Cannot insert a value for auto-increment primary key (' . UserPeer::ID . ')'); 878 } 879 880 // check the columns in natural order for more readable SQL queries 881 if ($this->isColumnModified(UserPeer::ID)) { 882 $modifiedColumns[':p' . $index++] = '`ID`'; 883 } 884 if ($this->isColumnModified(UserPeer::USERNAME)) { 885 $modifiedColumns[':p' . $index++] = '`USERNAME`'; 886 } 887 if ($this->isColumnModified(UserPeer::EMAIL)) { 888 $modifiedColumns[':p' . $index++] = '`EMAIL`'; 889 } 890 if ($this->isColumnModified(UserPeer::SALT)) { 891 $modifiedColumns[':p' . $index++] = '`SALT`'; 892 } 893 if ($this->isColumnModified(UserPeer::PASSWORD)) { 894 $modifiedColumns[':p' . $index++] = '`PASSWORD`'; 895 } 896 if ($this->isColumnModified(UserPeer::ROLE_ID)) { 897 $modifiedColumns[':p' . $index++] = '`ROLE_ID`'; 898 } 899 if ($this->isColumnModified(UserPeer::LOGIN_FAILURE_COUNT)) { 900 $modifiedColumns[':p' . $index++] = '`LOGIN_FAILURE_COUNT`'; 901 } 902 if ($this->isColumnModified(UserPeer::LOGIN_FAILURE_DATE)) { 903 $modifiedColumns[':p' . $index++] = '`LOGIN_FAILURE_DATE`'; 904 } 905 if ($this->isColumnModified(UserPeer::TREE_LEFT)) { 906 $modifiedColumns[':p' . $index++] = '`TREE_LEFT`'; 907 } 908 if ($this->isColumnModified(UserPeer::TREE_RIGHT)) { 909 $modifiedColumns[':p' . $index++] = '`TREE_RIGHT`'; 910 } 911 if ($this->isColumnModified(UserPeer::TREE_LEVEL)) { 912 $modifiedColumns[':p' . $index++] = '`TREE_LEVEL`'; 913 } 914 915 $sql = sprintf( 916 'INSERT INTO `user` (%s) VALUES (%s)', 917 implode(', ', $modifiedColumns), 918 implode(', ', array_keys($modifiedColumns)) 919 ); 920 921 try { 922 $stmt = $con->prepare($sql); 923 foreach ($modifiedColumns as $identifier => $columnName) { 924 switch ($columnName) { 925 case '`ID`': 926 $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT); 927 break; 928 case '`USERNAME`': 929 $stmt->bindValue($identifier, $this->username, PDO::PARAM_STR); 930 break; 931 case '`EMAIL`': 932 $stmt->bindValue($identifier, $this->email, PDO::PARAM_STR); 933 break; 934 case '`SALT`': 935 $stmt->bindValue($identifier, $this->salt, PDO::PARAM_STR); 936 break; 937 case '`PASSWORD`': 938 $stmt->bindValue($identifier, $this->password, PDO::PARAM_STR); 939 break; 940 case '`ROLE_ID`': 941 $stmt->bindValue($identifier, $this->role_id, PDO::PARAM_INT); 942 break; 943 case '`LOGIN_FAILURE_COUNT`': 944 $stmt->bindValue($identifier, $this->login_failure_count, PDO::PARAM_INT); 945 break; 946 case '`LOGIN_FAILURE_DATE`': 947 $stmt->bindValue($identifier, $this->login_failure_date, PDO::PARAM_STR); 948 break; 949 case '`TREE_LEFT`': 950 $stmt->bindValue($identifier, $this->tree_left, PDO::PARAM_INT); 951 break; 952 case '`TREE_RIGHT`': 953 $stmt->bindValue($identifier, $this->tree_right, PDO::PARAM_INT); 954 break; 955 case '`TREE_LEVEL`': 956 $stmt->bindValue($identifier, $this->tree_level, PDO::PARAM_INT); 957 break; 958 } 959 } 960 $stmt->execute(); 961 } catch (Exception $e) { 962 Propel::log($e->getMessage(), Propel::LOG_ERR); 963 throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e); 964 } 965 966 try { 967 $pk = $con->lastInsertId(); 968 } catch (Exception $e) { 969 throw new PropelException('Unable to get autoincrement id.', $e); 970 } 971 $this->setId($pk); 972 973 $this->setNew(false); 974 } 975 976 /** 977 * Update the row in the database. 978 * 979 * @param PropelPDO $con 980 * 981 * @see doSave() 982 */ 983 protected function doUpdate(PropelPDO $con) 984 { 985 $selectCriteria = $this->buildPkeyCriteria(); 986 $valuesCriteria = $this->buildCriteria(); 987 BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con); 988 } 837 989 838 990 /** … … 1338 1490 /** 1339 1491 * Initializes a collection based on the name of a relation. 1340 * Avoids crafting an 'init[$relationName]s' method name 1492 * Avoids crafting an 'init[$relationName]s' method name 1341 1493 * that wouldn't work when StandardEnglishPluralizer is used. 1342 1494 * … … 1420 1572 1421 1573 /** 1574 * Sets a collection of UserCredential objects related by a one-to-many relationship 1575 * to the current object. 1576 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 1577 * and new objects from the given Propel collection. 1578 * 1579 * @param PropelCollection $userCredentials A Propel collection. 1580 * @param PropelPDO $con Optional connection object 1581 */ 1582 public function setUserCredentials(PropelCollection $userCredentials, PropelPDO $con = null) 1583 { 1584 $this->userCredentialsScheduledForDeletion = $this->getUserCredentials(new Criteria(), $con)->diff($userCredentials); 1585 1586 foreach ($userCredentials as $userCredential) { 1587 // Fix issue with collection modified by reference 1588 if ($userCredential->isNew()) { 1589 $userCredential->setUser($this); 1590 } 1591 $this->addUserCredential($userCredential); 1592 } 1593 1594 $this->collUserCredentials = $userCredentials; 1595 } 1596 1597 /** 1422 1598 * Returns the number of related UserCredential objects. 1423 1599 * … … 1452 1628 * 1453 1629 * @param UserCredential $l UserCredential 1454 * @return void 1455 * @throws PropelException 1630 * @return User The current object (for fluent API support) 1456 1631 */ 1457 1632 public function addUserCredential(UserCredential $l) … … 1461 1636 } 1462 1637 if (!$this->collUserCredentials->contains($l)) { // only add it if the **same** object is not already associated 1463 $this->collUserCredentials[]= $l; 1464 $l->setUser($this); 1465 } 1638 $this->doAddUserCredential($l); 1639 } 1640 1641 return $this; 1642 } 1643 1644 /** 1645 * @param UserCredential $userCredential The userCredential object to add. 1646 */ 1647 protected function doAddUserCredential($userCredential) 1648 { 1649 $this->collUserCredentials[]= $userCredential; 1650 $userCredential->setUser($this); 1466 1651 } 1467 1652 … … 1555 1740 1556 1741 /** 1742 * Sets a collection of Credential objects related by a many-to-many relationship 1743 * to the current object by way of the user_credential cross-reference table. 1744 * It will also schedule objects for deletion based on a diff between old objects (aka persisted) 1745 * and new objects from the given Propel collection. 1746 * 1747 * @param PropelCollection $credentials A Propel collection. 1748 * @param PropelPDO $con Optional connection object 1749 */ 1750 public function setCredentials(PropelCollection $credentials, PropelPDO $con = null) 1751 { 1752 $userCredentials = UserCredentialQuery::create() 1753 ->filterByCredential($credentials) 1754 ->filterByUser($this) 1755 ->find($con); 1756 1757 $this->credentialsScheduledForDeletion = $this->getUserCredentials()->diff($userCredentials); 1758 $this->collUserCredentials = $userCredentials; 1759 1760 foreach ($credentials as $credential) { 1761 // Fix issue with collection modified by reference 1762 if ($credential->isNew()) { 1763 $this->doAddCredential($credential); 1764 } else { 1765 $this->addCredential($credential); 1766 } 1767 } 1768 1769 $this->collCredentials = $credentials; 1770 } 1771 1772 /** 1557 1773 * Gets the number of Credential objects related by a many-to-many relationship 1558 1774 * to the current object by way of the user_credential cross-reference table. … … 1596 1812 } 1597 1813 if (!$this->collCredentials->contains($credential)) { // only add it if the **same** object is not already associated 1598 $userCredential = new UserCredential(); 1599 $userCredential->setCredential($credential); 1600 $this->addUserCredential($userCredential); 1814 $this->doAddCredential($credential); 1601 1815 1602 1816 $this->collCredentials[]= $credential; 1603 1817 } 1818 } 1819 1820 /** 1821 * @param Credential $credential The credential object to add. 1822 */ 1823 protected function doAddCredential($credential) 1824 { 1825 $userCredential = new UserCredential(); 1826 $userCredential->setCredential($credential); 1827 $this->addUserCredential($userCredential); 1604 1828 } 1605 1829 … … 2015 2239 * Gets number of children for the given node 2016 2240 * 2017 * @param Criteria $criteria Criteria to filter results. 2241 * @param Criteria $criteria Criteria to filter results. 2018 2242 * @param PropelPDO $con Connection to use. 2019 2243 * @return int Number of children … … 2037 2261 * Gets the first child of the given node 2038 2262 * 2039 * @param Criteria $query Criteria to filter results. 2263 * @param Criteria $query Criteria to filter results. 2040 2264 * @param PropelPDO $con Connection to use. 2041 2265 * @return array List of User objects … … 2056 2280 * Gets the last child of the given node 2057 2281 * 2058 * @param Criteria $query Criteria to filter results. 2282 * @param Criteria $query Criteria to filter results. 2059 2283 * @param PropelPDO $con Connection to use. 2060 2284 * @return array List of User objects … … 2076 2300 * 2077 2301 * @param bool $includeNode Whether to include the current node or not 2078 * @param Criteria $query Criteria to filter results. 2302 * @param Criteria $query Criteria to filter results. 2079 2303 * @param PropelPDO $con Connection to use. 2080 2304 * … … 2099 2323 * Gets descendants for the given node 2100 2324 * 2101 * @param Criteria $query Criteria to filter results. 2325 * @param Criteria $query Criteria to filter results. 2102 2326 * @param PropelPDO $con Connection to use. 2103 2327 * @return array List of User objects … … 2118 2342 * Gets number of descendants for the given node 2119 2343 * 2120 * @param Criteria $query Criteria to filter results. 2344 * @param Criteria $query Criteria to filter results. 2121 2345 * @param PropelPDO $con Connection to use. 2122 2346 * @return int Number of descendants … … 2137 2361 * Gets descendants for the given node, plus the current node 2138 2362 * 2139 * @param Criteria $query Criteria to filter results. 2363 * @param Criteria $query Criteria to filter results. 2140 2364 * @param PropelPDO $con Connection to use. 2141 2365 * @return array List of User objects … … 2153 2377 * Use it for breadcrumb paths for instance 2154 2378 * 2155 * @param Criteria $query Criteria to filter results. 2379 * @param Criteria $query Criteria to filter results. 2156 2380 * @param PropelPDO $con Connection to use. 2157 2381 * @return array List of User objects … … 2209 2433 // update the children collection of the parent 2210 2434 $parent->addNestedSetChild($this); 2211 2435 2212 2436 // Keep the tree modification query for the save() transaction 2213 2437 $this->nestedSetQueries []= array( … … 2239 2463 // update the children collection of the parent 2240 2464 $parent->addNestedSetChild($this); 2241 2465 2242 2466 // Keep the tree modification query for the save() transaction 2243 2467 $this->nestedSetQueries []= array( … … 2319 2543 throw new PropelException('Cannot move a node as child of one of its subtree nodes.'); 2320 2544 } 2321 2545 2322 2546 $this->moveSubtreeTo($parent->getLeftValue() + 1, $parent->getLevel() - $this->getLevel() + 1, $con); 2323 2547 2324 2548 return $this; 2325 2549 } … … 2342 2566 throw new PropelException('Cannot move a node as child of one of its subtree nodes.'); 2343 2567 } 2344 2568 2345 2569 $this->moveSubtreeTo($parent->getRightValue(), $parent->getLevel() - $this->getLevel() + 1, $con); 2346 2570 2347 2571 return $this; 2348 2572 } … … 2368 2592 throw new PropelException('Cannot move a node as sibling of one of its subtree nodes.'); 2369 2593 } 2370 2594 2371 2595 $this->moveSubtreeTo($sibling->getLeftValue(), $sibling->getLevel() - $this->getLevel(), $con); 2372 2596 2373 2597 return $this; 2374 2598 } … … 2394 2618 throw new PropelException('Cannot move a node as sibling of one of its subtree nodes.'); 2395 2619 } 2396 2620 2397 2621 $this->moveSubtreeTo($sibling->getRightValue() + 1, $sibling->getLevel() - $this->getLevel(), $con); 2398 2622 2399 2623 return $this; 2400 2624 } … … 2413 2637 2414 2638 $treeSize = $right - $left +1; 2415 2639 2416 2640 if ($con === null) { 2417 2641 $con = Propel::getConnection(UserPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); 2418 2642 } 2419 2643 2420 2644 $con->beginTransaction(); 2421 2645 try { 2422 2646 // make room next to the target for the subtree 2423 2647 UserPeer::shiftRLValues($treeSize, $destLeft, null, $con); 2424 2648 2425 2649 if ($left >= $destLeft) { // src was shifted too? 2426 2650 $left += $treeSize; 2427 2651 $right += $treeSize; 2428 2652 } 2429 2653 2430 2654 if ($levelDelta) { 2431 2655 // update the levels of the subtree 2432 2656 UserPeer::shiftLevel($levelDelta, $left, $right, $con); 2433 2657 } 2434 2658 2435 2659 // move the subtree to the target 2436 2660 UserPeer::shiftRLValues($destLeft - $left, $left, $right, $con); 2437 2661 2438 2662 // remove the empty room at the previous location of the subtree 2439 2663 UserPeer::shiftRLValues(-$treeSize, $right + 1, null, $con); 2440 2664 2441 2665 // update all loaded nodes 2442 2666 UserPeer::updateLoadedNodes(null, $con); 2443 2667 2444 2668 $con->commit(); 2445 2669 } catch (PropelException $e) { … … 2451 2675 /** 2452 2676 * Deletes all descendants for the given node 2453 * Instance pooling is wiped out by this command, 2677 * Instance pooling is wiped out by this command, 2454 2678 * so existing User instances are probably invalid (except for the current one) 2455 2679 * … … 2475 2699 ->descendantsOf($this) 2476 2700 ->delete($con); 2477 2701 2478 2702 // fill up the room that was used by descendants 2479 2703 UserPeer::shiftRLValues($left - $right + 1, $right, null, $con); 2480 2704 2481 2705 // fix the right value for the current node, which is now a leaf 2482 2706 $this->setRightValue($left + 1); 2483 2707 2484 2708 $con->commit(); 2485 2709 } catch (Exception $e) { … … 2487 2711 throw $e; 2488 2712 } 2489 2713 2490 2714 return $ret; 2491 2715 } … … 2501 2725 } 2502 2726 2503 /**2504 * Catches calls to virtual methods2505 */2506 public function __call($name, $params)2507 {2508 if (preg_match('/get(\w+)/', $name, $matches)) {2509 $virtualColumn = $matches[1];2510 if ($this->hasVirtualColumn($virtualColumn)) {2511 return $this->getVirtualColumn($virtualColumn);2512 }2513 // no lcfirst in php<5.3...2514 $virtualColumn[0] = strtolower($virtualColumn[0]);2515 if ($this->hasVirtualColumn($virtualColumn)) {2516 return $this->getVirtualColumn($virtualColumn);2517 }2518 }2519 return parent::__call($name, $params);2520 }2521 2522 2727 } // BaseUser -
branches/Credentials/app/lib/propelom/om/BaseUserCredential.php
r48 r59 265 265 $con->beginTransaction(); 266 266 try { 267 $deleteQuery = UserCredentialQuery::create() 268 ->filterByPrimaryKey($this->getPrimaryKey()); 267 269 $ret = $this->preDelete($con); 268 270 if ($ret) { 269 UserCredentialQuery::create() 270 ->filterByPrimaryKey($this->getPrimaryKey()) 271 ->delete($con); 271 $deleteQuery->delete($con); 272 272 $this->postDelete($con); 273 273 $con->commit(); … … 276 276 $con->commit(); 277 277 } 278 } catch ( PropelException $e) {278 } catch (Exception $e) { 279 279 $con->rollBack(); 280 280 throw $e; … … 328 328 $con->commit(); 329 329 return $affectedRows; 330 } catch ( PropelException $e) {330 } catch (Exception $e) { 331 331 $con->rollBack(); 332 332 throw $e; … … 370 370 } 371 371 372 373 // If this object has been modified, then save it to the database. 374 if ($this->isModified()) { 372 if ($this->isNew() || $this->isModified()) { 373 // persist changes 375 374 if ($this->isNew()) { 376 $criteria = $this->buildCriteria(); 377 $pk = BasePeer::doInsert($criteria, $con); 378 $affectedRows += 1; 379 $this->setNew(false); 375 $this->doInsert($con); 380 376 } else { 381 $ affectedRows += UserCredentialPeer::doUpdate($this,$con);377 $this->doUpdate($con); 382 378 } 383 384 $this->resetModified(); // [HL] After being saved an object is no longer 'modified'379 $affectedRows += 1; 380 $this->resetModified(); 385 381 } 386 382 … … 390 386 return $affectedRows; 391 387 } // doSave() 388 389 /** 390 * Insert the row in the database. 391 * 392 * @param PropelPDO $con 393 * 394 * @throws PropelException 395 * @see doSave() 396 */ 397 protected function doInsert(PropelPDO $con) 398 { 399 $modifiedColumns = array(); 400 $index = 0; 401 402 403 // check the columns in natural order for more readable SQL queries 404 if ($this->isColumnModified(UserCredentialPeer::USER_ID)) { 405 $modifiedColumns[':p' . $index++] = '`USER_ID`'; 406 } 407 if ($this->isColumnModified(UserCredentialPeer::CREDENTIAL_ID)) { 408 $modifiedColumns[':p' . $index++] = '`CREDENTIAL_ID`'; 409 } 410 411 $sql = sprintf( 412 'INSERT INTO `user_credential` (%s) VALUES (%s)', 413 implode(', ', $modifiedColumns), 414 implode(', ', array_keys($modifiedColumns)) 415 ); 416 417 try { 418 $stmt = $con->prepare($sql); 419 foreach ($modifiedColumns as $identifier => $columnName) { 420 switch ($columnName) { 421 case '`USER_ID`': 422 $stmt->bindValue($identifier, $this->user_id, PDO::PARAM_INT); 423 break; 424 case '`CREDENTIAL_ID`': 425 $stmt->bindValue($identifier, $this->credential_id, PDO::PARAM_INT); 426 break; 427 } 428 } 429 $stmt->execute(); 430 } catch (Exception $e) { 431 Propel::log($e->getMessage(), Propel::LOG_ERR); 432 throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), $e); 433 } 434 435 $this->setNew(false); 436 } 437 438 /** 439 * Update the row in the database. 440 * 441 * @param PropelPDO $con 442 * 443 * @see doSave() 444 */ 445 protected function doUpdate(PropelPDO $con) 446 { 447 $selectCriteria = $this->buildPkeyCriteria(); 448 $valuesCriteria = $this->buildCriteria(); 449 BasePeer::doUpdate($selectCriteria, $valuesCriteria, $con); 450 } 392 451 393 452 /** … … 883 942 } 884 943 885 /**886 * Catches calls to virtual methods887 */888 public function __call($name, $params)889 {890 if (preg_match('/get(\w+)/', $name, $matches)) {891 $virtualColumn = $matches[1];892 if ($this->hasVirtualColumn($virtualColumn)) {893 return $this->getVirtualColumn($virtualColumn);894 }895 // no lcfirst in php<5.3...896 $virtualColumn[0] = strtolower($virtualColumn[0]);897 if ($this->hasVirtualColumn($virtualColumn)) {898 return $this->getVirtualColumn($virtualColumn);899 }900 }901 return parent::__call($name, $params);902 }903 904 944 } // BaseUserCredential -
branches/Credentials/app/lib/propelom/om/BaseUserCredentialPeer.php
r48 r59 25 25 /** the related TableMap class for this table */ 26 26 const TM_CLASS = 'UserCredentialTableMap'; 27 27 28 28 /** The total number of columns. */ 29 29 const NUM_COLUMNS = 2; … … 43 43 /** The default string format for model objects of the related table **/ 44 44 const DEFAULT_STRING_FORMAT = 'YAML'; 45 45 46 46 /** 47 47 * An identiy map to hold any loaded instances of UserCredential objects. … … 372 372 373 373 /** 374 * Retrieves the primary key from the DB resultset row 374 * Retrieves the primary key from the DB resultset row 375 375 * For tables with a single-column primary key, that simple pkey value will be returned. For tables with 376 376 * a multi-column primary key, an array of the primary key columns will be returned. … … 469 469 UserCredentialPeer::addSelectColumns($criteria); 470 470 } 471 471 472 472 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count 473 473 474 474 // Set the correct dbName 475 475 $criteria->setDbName(self::DATABASE_NAME); … … 519 519 UserCredentialPeer::addSelectColumns($criteria); 520 520 } 521 521 522 522 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count 523 523 524 524 // Set the correct dbName 525 525 $criteria->setDbName(self::DATABASE_NAME); … … 701 701 UserCredentialPeer::addSelectColumns($criteria); 702 702 } 703 703 704 704 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count 705 705 706 706 // Set the correct dbName 707 707 $criteria->setDbName(self::DATABASE_NAME); … … 836 836 // tables go into the FROM clause. 837 837 $criteria->setPrimaryTableName(UserCredentialPeer::TABLE_NAME); 838 838 839 839 if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { 840 840 $criteria->setDistinct(); … … 844 844 UserCredentialPeer::addSelectColumns($criteria); 845 845 } 846 846 847 847 $criteria->clearOrderByColumns(); // ORDER BY should not affect count 848 848 849 849 // Set the correct dbName 850 850 $criteria->setDbName(self::DATABASE_NAME); … … 886 886 // tables go into the FROM clause. 887 887 $criteria->setPrimaryTableName(UserCredentialPeer::TABLE_NAME); 888 888 889 889 if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { 890 890 $criteria->setDistinct(); … … 894 894 UserCredentialPeer::addSelectColumns($criteria); 895 895 } 896 896 897 897 $criteria->clearOrderByColumns(); // ORDER BY should not affect count 898 898 899 899 // Set the correct dbName 900 900 $criteria->setDbName(self::DATABASE_NAME); -
branches/Credentials/app/lib/propelom/om/BaseUserCredentialQuery.php
r48 r59 38 38 abstract class BaseUserCredentialQuery extends ModelCriteria 39 39 { 40 40 41 41 /** 42 42 * Initializes internal state of BaseUserCredentialQuery object. … … 75 75 76 76 /** 77 * Find object by primary key 77 * Find object by primary key. 78 * Propel uses the instance pool to skip the database if the object exists. 79 * Go fast if the query is untouched. 80 * 78 81 * <code> 79 82 * $obj = $c->findPk(array(12, 34), $con); 80 83 * </code> 84 * 81 85 * @param array[$user_id, $credential_id] $key Primary key to use for the query 82 86 * @param PropelPDO $con an optional connection object … … 86 90 public function findPk($key, $con = null) 87 91 { 88 if ((null !== ($obj = UserCredentialPeer::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && $this->getFormatter()->isObjectFormatter()) { 92 if ($key === null) { 93 return null; 94 } 95 if ((null !== ($obj = UserCredentialPeer::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) { 89 96 // the object is alredy in the instance pool 90 97 return $obj; 98 } 99 if ($con === null) { 100 $con = Propel::getConnection(UserCredentialPeer::DATABASE_NAME, Propel::CONNECTION_READ); 101 } 102 $this->basePreSelect($con); 103 if ($this->formatter || $this->modelAlias || $this->with || $this->select 104 || $this->selectColumns || $this->asColumns || $this->selectModifiers 105 || $this->map || $this->having || $this->joins) { 106 return $this->findPkComplex($key, $con); 91 107 } else { 92 // the object has not been requested yet, or the formatter is not an object formatter 93 $criteria = $this->isKeepQuery() ? clone $this : $this; 94 $stmt = $criteria 95 ->filterByPrimaryKey($key) 96 ->getSelectStatement($con); 97 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 98 } 108 return $this->findPkSimple($key, $con); 109 } 110 } 111 112 /** 113 * Find object by primary key using raw SQL to go fast. 114 * Bypass doSelect() and the object formatter by using generated code. 115 * 116 * @param mixed $key Primary key to use for the query 117 * @param PropelPDO $con A connection object 118 * 119 * @return UserCredential A model object, or null if the key is not found 120 */ 121 protected function findPkSimple($key, $con) 122 { 123 $sql = 'SELECT `USER_ID`, `CREDENTIAL_ID` FROM `user_credential` WHERE `USER_ID` = :p0 AND `CREDENTIAL_ID` = :p1'; 124 try { 125 $stmt = $con->prepare($sql); 126 $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT); 127 $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT); 128 $stmt->execute(); 129 } catch (Exception $e) { 130 Propel::log($e->getMessage(), Propel::LOG_ERR); 131 throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); 132 } 133 $obj = null; 134 if ($row = $stmt->fetch(PDO::FETCH_NUM)) { 135 $obj = new UserCredential(); 136 $obj->hydrate($row); 137 UserCredentialPeer::addInstanceToPool($obj, serialize(array((string) $row[0], (string) $row[1]))); 138 } 139 $stmt->closeCursor(); 140 141 return $obj; 142 } 143 144 /** 145 * Find object by primary key. 146 * 147 * @param mixed $key Primary key to use for the query 148 * @param PropelPDO $con A connection object 149 * 150 * @return UserCredential|array|mixed the result, formatted by the current formatter 151 */ 152 protected function findPkComplex($key, $con) 153 { 154 // As the query uses a PK condition, no limit(1) is necessary. 155 $criteria = $this->isKeepQuery() ? clone $this : $this; 156 $stmt = $criteria 157 ->filterByPrimaryKey($key) 158 ->doSelect($con); 159 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 99 160 } 100 161 … … 111 172 public function findPks($keys, $con = null) 112 173 { 174 if ($con === null) { 175 $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ); 176 } 177 $this->basePreSelect($con); 113 178 $criteria = $this->isKeepQuery() ? clone $this : $this; 114 return $this179 $stmt = $criteria 115 180 ->filterByPrimaryKeys($keys) 116 ->find($con); 181 ->doSelect($con); 182 return $criteria->getFormatter()->init($criteria)->format($stmt); 117 183 } 118 184 … … 128 194 $this->addUsingAlias(UserCredentialPeer::USER_ID, $key[0], Criteria::EQUAL); 129 195 $this->addUsingAlias(UserCredentialPeer::CREDENTIAL_ID, $key[1], Criteria::EQUAL); 130 196 131 197 return $this; 132 198 } … … 150 216 $this->addOr($cton0); 151 217 } 152 218 153 219 return $this; 154 220 } … … 156 222 /** 157 223 * Filter the query on the user_id column 158 * 224 * 159 225 * Example usage: 160 226 * <code> … … 184 250 /** 185 251 * Filter the query on the credential_id column 186 * 252 * 187 253 * Example usage: 188 254 * <code> … … 236 302 /** 237 303 * Adds a JOIN clause to the query using the User relation 238 * 304 * 239 305 * @param string $relationAlias optional alias for the relation 240 306 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 246 312 $tableMap = $this->getTableMap(); 247 313 $relationMap = $tableMap->getRelation('User'); 248 314 249 315 // create a ModelJoin object for this join 250 316 $join = new ModelJoin(); … … 254 320 $join->setPreviousJoin($previousJoin); 255 321 } 256 322 257 323 // add the ModelJoin to the current object 258 324 if($relationAlias) { … … 262 328 $this->addJoinObject($join, 'User'); 263 329 } 264 330 265 331 return $this; 266 332 } … … 270 336 * 271 337 * @see useQuery() 272 * 338 * 273 339 * @param string $relationAlias optional alias for the relation, 274 340 * to be used as main alias in the secondary query … … 310 376 /** 311 377 * Adds a JOIN clause to the query using the Credential relation 312 * 378 * 313 379 * @param string $relationAlias optional alias for the relation 314 380 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 320 386 $tableMap = $this->getTableMap(); 321 387 $relationMap = $tableMap->getRelation('Credential'); 322 388 323 389 // create a ModelJoin object for this join 324 390 $join = new ModelJoin(); … … 328 394 $join->setPreviousJoin($previousJoin); 329 395 } 330 396 331 397 // add the ModelJoin to the current object 332 398 if($relationAlias) { … … 336 402 $this->addJoinObject($join, 'Credential'); 337 403 } 338 404 339 405 return $this; 340 406 } … … 344 410 * 345 411 * @see useQuery() 346 * 412 * 347 413 * @param string $relationAlias optional alias for the relation, 348 414 * to be used as main alias in the secondary query … … 371 437 $this->addCond('pruneCond1', $this->getAliasedColName(UserCredentialPeer::CREDENTIAL_ID), $userCredential->getCredentialId(), Criteria::NOT_EQUAL); 372 438 $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR); 373 }374 439 } 440 375 441 return $this; 376 442 } -
branches/Credentials/app/lib/propelom/om/BaseUserPeer.php
r48 r59 25 25 /** the related TableMap class for this table */ 26 26 const TM_CLASS = 'UserTableMap'; 27 27 28 28 /** The total number of columns. */ 29 29 const NUM_COLUMNS = 11; … … 70 70 /** The default string format for model objects of the related table **/ 71 71 const DEFAULT_STRING_FORMAT = 'YAML'; 72 72 73 73 /** 74 74 * An identiy map to hold any loaded instances of User objects. … … 434 434 435 435 /** 436 * Retrieves the primary key from the DB resultset row 436 * Retrieves the primary key from the DB resultset row 437 437 * For tables with a single-column primary key, that simple pkey value will be returned. For tables with 438 438 * a multi-column primary key, an array of the primary key columns will be returned. … … 531 531 UserPeer::addSelectColumns($criteria); 532 532 } 533 533 534 534 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count 535 535 536 536 // Set the correct dbName 537 537 $criteria->setDbName(self::DATABASE_NAME); … … 647 647 UserPeer::addSelectColumns($criteria); 648 648 } 649 649 650 650 $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count 651 651 652 652 // Set the correct dbName 653 653 $criteria->setDbName(self::DATABASE_NAME); … … 1065 1065 } 1066 1066 $criteria->addAscendingOrderByColumn(UserPeer::LEFT_COL); 1067 1067 1068 1068 return UserPeer::doSelect($criteria, $con); 1069 1069 } … … 1118 1118 } 1119 1119 $whereCriteria->add($criterion); 1120 1120 1121 1121 $valuesCriteria = new Criteria(UserPeer::DATABASE_NAME); 1122 1122 $valuesCriteria->add(UserPeer::LEFT_COL, array('raw' => UserPeer::LEFT_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL); … … 1156 1156 $whereCriteria->add(UserPeer::LEFT_COL, $first, Criteria::GREATER_EQUAL); 1157 1157 $whereCriteria->add(UserPeer::RIGHT_COL, $last, Criteria::LESS_EQUAL); 1158 1158 1159 1159 $valuesCriteria = new Criteria(UserPeer::DATABASE_NAME); 1160 1160 $valuesCriteria->add(UserPeer::LEVEL_COL, array('raw' => UserPeer::LEVEL_COL . ' + ?', 'value' => $delta), Criteria::CUSTOM_EQUAL); … … 1239 1239 UserPeer::addInstanceToPool($obj, $key); 1240 1240 } 1241 1241 1242 1242 // compute level 1243 1243 // Algorithm shamelessly stolen from sfPropelActAsNestedSetBehaviorPlugin … … 1254 1254 $prev[$i] = $obj->getRightValue(); 1255 1255 } 1256 1256 1257 1257 // update level in node if necessary 1258 1258 if ($obj->getLevel() !== $level) { -
branches/Credentials/app/lib/propelom/om/BaseUserQuery.php
r48 r59 74 74 abstract class BaseUserQuery extends ModelCriteria 75 75 { 76 76 77 77 /** 78 78 * Initializes internal state of BaseUserQuery object. … … 111 111 112 112 /** 113 * Find object by primary key 114 * Use instance pooling to avoid a database query if the object exists 113 * Find object by primary key. 114 * Propel uses the instance pool to skip the database if the object exists. 115 * Go fast if the query is untouched. 116 * 115 117 * <code> 116 118 * $obj = $c->findPk(12, $con); 117 119 * </code> 120 * 118 121 * @param mixed $key Primary key to use for the query 119 122 * @param PropelPDO $con an optional connection object … … 123 126 public function findPk($key, $con = null) 124 127 { 125 if ((null !== ($obj = UserPeer::getInstanceFromPool((string) $key))) && $this->getFormatter()->isObjectFormatter()) { 128 if ($key === null) { 129 return null; 130 } 131 if ((null !== ($obj = UserPeer::getInstanceFromPool((string) $key))) && !$this->formatter) { 126 132 // the object is alredy in the instance pool 127 133 return $obj; 134 } 135 if ($con === null) { 136 $con = Propel::getConnection(UserPeer::DATABASE_NAME, Propel::CONNECTION_READ); 137 } 138 $this->basePreSelect($con); 139 if ($this->formatter || $this->modelAlias || $this->with || $this->select 140 || $this->selectColumns || $this->asColumns || $this->selectModifiers 141 || $this->map || $this->having || $this->joins) { 142 return $this->findPkComplex($key, $con); 128 143 } else { 129 // the object has not been requested yet, or the formatter is not an object formatter 130 $criteria = $this->isKeepQuery() ? clone $this : $this; 131 $stmt = $criteria 132 ->filterByPrimaryKey($key) 133 ->getSelectStatement($con); 134 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 135 } 144 return $this->findPkSimple($key, $con); 145 } 146 } 147 148 /** 149 * Find object by primary key using raw SQL to go fast. 150 * Bypass doSelect() and the object formatter by using generated code. 151 * 152 * @param mixed $key Primary key to use for the query 153 * @param PropelPDO $con A connection object 154 * 155 * @return User A model object, or null if the key is not found 156 */ 157 protected function findPkSimple($key, $con) 158 { 159 $sql = 'SELECT `ID`, `USERNAME`, `EMAIL`, `SALT`, `PASSWORD`, `ROLE_ID`, `LOGIN_FAILURE_COUNT`, `LOGIN_FAILURE_DATE`, `TREE_LEFT`, `TREE_RIGHT`, `TREE_LEVEL` FROM `user` WHERE `ID` = :p0'; 160 try { 161 $stmt = $con->prepare($sql); 162 $stmt->bindValue(':p0', $key, PDO::PARAM_INT); 163 $stmt->execute(); 164 } catch (Exception $e) { 165 Propel::log($e->getMessage(), Propel::LOG_ERR); 166 throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e); 167 } 168 $obj = null; 169 if ($row = $stmt->fetch(PDO::FETCH_NUM)) { 170 $obj = new User(); 171 $obj->hydrate($row); 172 UserPeer::addInstanceToPool($obj, (string) $row[0]); 173 } 174 $stmt->closeCursor(); 175 176 return $obj; 177 } 178 179 /** 180 * Find object by primary key. 181 * 182 * @param mixed $key Primary key to use for the query 183 * @param PropelPDO $con A connection object 184 * 185 * @return User|array|mixed the result, formatted by the current formatter 186 */ 187 protected function findPkComplex($key, $con) 188 { 189 // As the query uses a PK condition, no limit(1) is necessary. 190 $criteria = $this->isKeepQuery() ? clone $this : $this; 191 $stmt = $criteria 192 ->filterByPrimaryKey($key) 193 ->doSelect($con); 194 return $criteria->getFormatter()->init($criteria)->formatOne($stmt); 136 195 } 137 196 … … 148 207 public function findPks($keys, $con = null) 149 208 { 209 if ($con === null) { 210 $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ); 211 } 212 $this->basePreSelect($con); 150 213 $criteria = $this->isKeepQuery() ? clone $this : $this; 151 return $this214 $stmt = $criteria 152 215 ->filterByPrimaryKeys($keys) 153 ->find($con); 216 ->doSelect($con); 217 return $criteria->getFormatter()->init($criteria)->format($stmt); 154 218 } 155 219 … … 180 244 /** 181 245 * Filter the query on the id column 182 * 246 * 183 247 * Example usage: 184 248 * <code> … … 206 270 /** 207 271 * Filter the query on the username column 208 * 272 * 209 273 * Example usage: 210 274 * <code> … … 234 298 /** 235 299 * Filter the query on the email column 236 * 300 * 237 301 * Example usage: 238 302 * <code> … … 262 326 /** 263 327 * Filter the query on the salt column 264 * 328 * 265 329 * Example usage: 266 330 * <code> … … 290 354 /** 291 355 * Filter the query on the password column 292 * 356 * 293 357 * Example usage: 294 358 * <code> … … 318 382 /** 319 383 * Filter the query on the role_id column 320 * 384 * 321 385 * Example usage: 322 386 * <code> … … 360 424 /** 361 425 * Filter the query on the login_failure_count column 362 * 426 * 363 427 * Example usage: 364 428 * <code> … … 400 464 /** 401 465 * Filter the query on the login_failure_date column 402 * 466 * 403 467 * Example usage: 404 468 * <code> … … 442 506 /** 443 507 * Filter the query on the tree_left column 444 * 508 * 445 509 * Example usage: 446 510 * <code> … … 482 546 /** 483 547 * Filter the query on the tree_right column 484 * 548 * 485 549 * Example usage: 486 550 * <code> … … 522 586 /** 523 587 * Filter the query on the tree_level column 524 * 588 * 525 589 * Example usage: 526 590 * <code> … … 586 650 /** 587 651 * Adds a JOIN clause to the query using the Role relation 588 * 652 * 589 653 * @param string $relationAlias optional alias for the relation 590 654 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 596 660 $tableMap = $this->getTableMap(); 597 661 $relationMap = $tableMap->getRelation('Role'); 598 662 599 663 // create a ModelJoin object for this join 600 664 $join = new ModelJoin(); … … 604 668 $join->setPreviousJoin($previousJoin); 605 669 } 606 670 607 671 // add the ModelJoin to the current object 608 672 if($relationAlias) { … … 612 676 $this->addJoinObject($join, 'Role'); 613 677 } 614 678 615 679 return $this; 616 680 } … … 620 684 * 621 685 * @see useQuery() 622 * 686 * 623 687 * @param string $relationAlias optional alias for the relation, 624 688 * to be used as main alias in the secondary query … … 650 714 return $this 651 715 ->useUserCredentialQuery() 652 ->filterByPrimaryKeys($userCredential->getPrimaryKeys())716 ->filterByPrimaryKeys($userCredential->getPrimaryKeys()) 653 717 ->endUse(); 654 718 } else { … … 659 723 /** 660 724 * Adds a JOIN clause to the query using the UserCredential relation 661 * 725 * 662 726 * @param string $relationAlias optional alias for the relation 663 727 * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' … … 669 733 $tableMap = $this->getTableMap(); 670 734 $relationMap = $tableMap->getRelation('UserCredential'); 671 735 672 736 // create a ModelJoin object for this join 673 737 $join = new ModelJoin(); … … 677 741 $join->setPreviousJoin($previousJoin); 678 742 } 679 743 680 744 // add the ModelJoin to the current object 681 745 if($relationAlias) { … … 685 749 $this->addJoinObject($join, 'UserCredential'); 686 750 } 687 751 688 752 return $this; 689 753 } … … 693 757 * 694 758 * @see useQuery() 695 * 759 * 696 760 * @param string $relationAlias optional alias for the relation, 697 761 * to be used as main alias in the secondary query … … 720 784 return $this 721 785 ->useUserCredentialQuery() 722 ->filterByCredential($credential, $comparison)786 ->filterByCredential($credential, $comparison) 723 787 ->endUse(); 724 788 } 725 789 726 790 /** 727 791 * Exclude object from result … … 735 799 if ($user) { 736 800 $this->addUsingAlias(UserPeer::ID, $user->getId(), Criteria::NOT_EQUAL); 737 }738 801 } 802 739 803 return $this; 740 804 }
Note: See TracChangeset
for help on using the changeset viewer.
