PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/propelorm/generator/lib/behavior/archivable/templates/objectArchive.php

https://bitbucket.org/franhb/propel
PHP | 29 lines | 16 code | 1 blank | 12 comment | 5 complexity | 44beef03022250e7f03bf97a7b7a3ed8 MD5 | raw file
Possible License(s): LGPL-3.0
  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 PropelPDO $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(PropelPDO $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. if (!$archive = $this->getArchive(<?php if(!$hasArchiveClass): ?>$con<?php endif; ?>)) {
  19. $archive = new <?php echo $archiveTablePhpName ?>();
  20. $archive->setPrimaryKey($this->getPrimaryKey());
  21. }
  22. $this->copyInto($archive, $deepCopy = false, $makeNew = false);
  23. <?php if ($archivedAtColumn): ?>
  24. $archive->set<?php echo $archivedAtColumn->getPhpName() ?>(time());
  25. <?php endif; ?>
  26. $archive->save(<?php if(!$hasArchiveClass): ?>$con<?php endif; ?>);
  27. return $archive;
  28. }