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

Commit

Permalink
Extract Clip_Doctrine_Pubdata->validateUrltitle to be used where need…
Browse files Browse the repository at this point in the history
…ed. Refs #9 and #56
  • Loading branch information
matheo committed Feb 10, 2012
1 parent 49c6c1c commit 4a4d5f9
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/modules/Clip/lib/Clip/Doctrine/Pubdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,28 @@ public function notifyHooks($hooktype)
ServiceUtil::getManager()->getService('zikula.hookmanager')->notify($hook);
}

/**
* urltitle corrector.
*
* @return void
*/
public function validateUrltitle()
{
if (!$this->core_urltitle) {
return;
}

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

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

$pid = $this->getTable()->selectFieldBy('core_pid', $this->core_urltitle, 'core_urltitle');
}
}

/**
* preInsert hook.
*
Expand Down Expand Up @@ -501,15 +523,7 @@ public function preSave($event)
$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');
}
$pub->validateUrltitle();

// invoke the preSave hook on pubfields
if (isset($pub['core_tid'])) {
Expand Down

0 comments on commit 4a4d5f9

Please sign in to comment.