PageRenderTime 34ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Propel/Generator/Behavior/Archivable/templates/queryArchive.php

http://github.com/propelorm/Propel2
PHP | 39 lines | 19 code | 4 blank | 16 comment | 2 complexity | d5f704d2cce285b4938019890e190594 MD5 | raw file
  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 ConnectionInterface $con Connection to use.
  9. * @param Boolean $useLittleMemory Whether or not to use OnDemandFormatter 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. */
  15. public function archive($con = null, $useLittleMemory = true)
  16. {
  17. $criteria = clone $this;
  18. // prepare the query
  19. $criteria->setWith(array());
  20. if ($useLittleMemory) {
  21. $criteria->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
  22. }
  23. if ($con === null) {
  24. $con = Propel::getServiceContainer()->getWriteConnection(<?php echo $modelTableMap ?>::DATABASE_NAME);
  25. }
  26. return $con->transaction(function () use ($con, $criteria) {
  27. $totalArchivedObjects = 0;
  28. // archive all results one by one
  29. foreach ($criteria->find($con) as $object) {
  30. $object->archive($con);
  31. $totalArchivedObjects++;
  32. }
  33. return $totalArchivedObjects;
  34. });
  35. }