Guite/MostGenerator — Issue #158: Re-Use function on entities gives errors
Author: espaan
Created: 2012-02-24 18:13:24+00:00
State: open

One of the subadmin users on my track&field site tried the re-use option on an entity.
He got error messages, but the new entity was created, however the old entity was deleted, so it was in fact
an edit operation instead of a copy, which was of course not intended.

Messages were:
Error! Creation attempt failed.
Error! Invalid identifier received.

Reply over email was a hack in the Formhandler
Quote : There I tried this change in the FormHandler Base class (method initEntityForCreation) to make it work...

'''
if ($this->hasTemplateId === true) {
$templateIdValues = array();
$i = 0;
foreach ($this->idFields as $idField) {
$templateIdValues[$idField] = $templateIdValueParts[$i];
$i++;
}
// reuse existing entity
/* $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $this->objectType, 'id' => $templateIdValues));
if ($entity == null) {
return LogUtil::registerError($this->__('No such item.'));
}
foreach ($this->idFields as $idField) {
$entity[$idField] = null;
}*/
/** HACK */
$entityT = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $this->objectType, 'id' => $templateIdValues));
if (!is_object($entityT) || !isset($entityT['id'])) {
return LogUtil::registerError($this->__('No such item.'));
}
$entityClass = $this->name . '_Entity_' . ucfirst($this->objectType);
$entity = new $entityClass();
$entity->setName($entityT->getName());
$entity->setDescription($entityT->getDescription());
$entity->setActivity($entityT->getActivity());
foreach ($entityT->getProperties() as $property) {
$entity->addProperties($property);
}
$entity->setGroup($entityT->getGroup());
/** HACK END */
}
else {
$entityClass = $this->name . '_Entity_' . ucfirst($this->objectType);
$entity = new $entityClass();
}
'''