PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/propel_16/vendor/propel/generator/lib/behavior/archivable/templates/queryArchive.php

http://github.com/eventhorizonpl/forked-php-orm-benchmark
PHP | 43 lines | 24 code | 2 blank | 17 comment | 2 complexity | 3d3c20cd333c95f732ac04c826862a70 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0
  1. /**
  2. * Copy the data of the objects satisfying the query into <?php echo $archiveTablePhpName ?> archive objects.
  3. * The archived objects are then saved.
  4. * If any of the objects has already been archived, the archived object
  5. * is updated and not duplicated.
  6. * Warning: This termination methods issues 2n+1 queries.
  7. *
  8. * @param PropelPDO $con Connection to use.
  9. * @param Boolean $useLittleMemory Whether or not to use PropelOnDemandFormatter to retrieve objects.
  10. * Set to false if the identity map matters.
  11. * Set to true (default) to use less memory.
  12. *
  13. * @return int the number of archived objects
  14. * @throws PropelException
  15. */
  16. public function archive($con = null, $useLittleMemory = true)
  17. {
  18. $totalArchivedObjects = 0;
  19. $criteria = clone $this;
  20. // prepare the query
  21. $criteria->setWith(array());
  22. if ($useLittleMemory) {
  23. $criteria->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
  24. }
  25. if ($con === null) {
  26. $con = Propel::getConnection(<?php echo $modelPeerName ?>::DATABASE_NAME, Propel::CONNECTION_WRITE);
  27. }
  28. $con->beginTransaction();
  29. try {
  30. // archive all results one by one
  31. foreach ($criteria->find($con) as $object) {
  32. $object->archive($con);
  33. $totalArchivedObjects++;
  34. }
  35. $con->commit();
  36. } catch (PropelException $e) {
  37. $con->rollBack();
  38. throw $e;
  39. }
  40. return $totalArchivedObjects;
  41. }