/propelorm/generator/lib/behavior/archivable/templates/objectArchive.php
PHP | 29 lines | 16 code | 1 blank | 12 comment | 5 complexity | 44beef03022250e7f03bf97a7b7a3ed8 MD5 | raw file
Possible License(s): LGPL-3.0
- /**
- * Copy the data of the current object into a $archiveTablePhpName archive object.
- * The archived object is then saved.
- * If the current object has already been archived, the archived object
- * is updated and not duplicated.
- *
- * @param PropelPDO $con Optional connection object
- *
- * @throws PropelException If the object is new
- *
- * @return <?php echo $archiveTablePhpName ?> The archive object based on this object
- */
- public function archive(PropelPDO $con = null)
- {
- if ($this->isNew()) {
- throw new PropelException('New objects cannot be archived. You must save the current object before calling archive().');
- }
- if (!$archive = $this->getArchive(<?php if(!$hasArchiveClass): ?>$con<?php endif; ?>)) {
- $archive = new <?php echo $archiveTablePhpName ?>();
- $archive->setPrimaryKey($this->getPrimaryKey());
- }
- $this->copyInto($archive, $deepCopy = false, $makeNew = false);
- <?php if ($archivedAtColumn): ?>
- $archive->set<?php echo $archivedAtColumn->getPhpName() ?>(time());
- <?php endif; ?>
- $archive->save(<?php if(!$hasArchiveClass): ?>$con<?php endif; ?>);
- return $archive;
- }