PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/propelorm/Propel2
PHP | 30 lines | 17 code | 1 blank | 12 comment | 5 complexity | f69331401e3b1eace094a6db786e5b36 MD5 | raw file
  1. /**
  2. * Copy the data of the current object into a $archiveTablePhpName archive object.
  3. * The archived object is then saved.
  4. * If the current object has already been archived, the archived object
  5. * is updated and not duplicated.
  6. *
  7. * @param ConnectionInterface $con Optional connection object
  8. *
  9. * @throws PropelException If the object is new
  10. *
  11. * @return <?php echo $archiveTablePhpName ?> The archive object based on this object
  12. */
  13. public function archive(ConnectionInterface $con = null)
  14. {
  15. if ($this->isNew()) {
  16. throw new PropelException('New objects cannot be archived. You must save the current object before calling archive().');
  17. }
  18. $archive = $this->getArchive(<?php if (!$hasArchiveClass): ?>$con<?php endif; ?>);
  19. if (!$archive) {
  20. $archive = new <?php echo $archiveTablePhpName ?>();
  21. $archive->setPrimaryKey($this->getPrimaryKey());
  22. }
  23. $this->copyInto($archive, $deepCopy = false, $makeNew = false);
  24. <?php if ($archivedAtColumn): ?>
  25. $archive->set<?php echo $archivedAtColumn->getPhpName() ?>(time());
  26. <?php endif; ?>
  27. $archive->save(<?php if (!$hasArchiveClass): ?>$con<?php endif; ?>);
  28. return $archive;
  29. }