Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
urltitle fix in case of no pubfield title marked. Refs #9 Closes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
matheo committed Jan 6, 2012
1 parent 318c511 commit f50ba71
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/modules/Clip/lib/Clip/Doctrine/Pubdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,22 @@ public function preSave($event)
{
$pub = $event->getInvoker();

// figures out a publication id
if (!$pub['core_pid']) {
$pub['core_pid'] = $this->getTable()->selectFieldFunction('core_pid', 'MAX') + 1;
}

// fills the urltitle
if (!$pub['core_urltitle']) {
$pub['core_urltitle'] = substr(DataUtil::formatPermalink($pub[$pub['core_titlefield']]), 0, 255);
$urltitle = $pub[$pub['core_titlefield']] ? $pub[$pub['core_titlefield']] : $pub['core_pid'];
$pub['core_urltitle'] = substr(DataUtil::formatPermalink($urltitle), 0, 255);
}

// validate the unique urltitle
$pid = $this->getTable()->selectFieldBy('core_pid', $pub['core_urltitle'], 'core_urltitle');

while ($pid && $pid != $pub['core_pid']) {
// TODO better to throw a validation exception
++$pub->core_urltitle;

$pid = $this->getTable()->selectFieldBy('core_pid', $pub['core_urltitle'], 'core_urltitle');
Expand Down

0 comments on commit f50ba71

Please sign in to comment.