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

Commit

Permalink
Workflow adjustments on publication's record. Refs #9 and #56
Browse files Browse the repository at this point in the history
  • Loading branch information
matheo committed Dec 20, 2011
1 parent 157640c commit f19f50c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 38 deletions.
66 changes: 61 additions & 5 deletions src/modules/Clip/lib/Clip/Doctrine/Pubdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,59 @@ public function getRelation($alias)
}

/**
* Save hooks.
* preInsert hook.
*
* @return void
*/
public function preInsert($event)
{
$pub = $event->getInvoker();

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

// assign the author
$pub['core_author'] = (int)UserUtil::getVar('uid');

// assign the language
if (is_null($pub['core_language'])) {
$pub['core_language'] = '';
}

// fills the publish date automatically
if (empty($pub['core_publishdate'])) {
$pub['core_publishdate'] = DateUtil::getDatetime();
}
}

/**
* preSave hook.
*
* @return void
*/
public function preSave($event)
{
$obj = $event->getInvoker();
$pub = $event->getInvoker();

if (isset($obj['core_tid'])) {
$pubfields = Clip_Util::getPubFields($obj['core_tid']);
// fills the urltitle
if (!$pub['core_urltitle']) {
$pub['core_urltitle'] = substr(DataUtil::formatPermalink($pub[$pub['core_titlefield']]), 0, 255);
}

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

while ($pid && $pid != $pub['core_pid']) {
++$pub->core_urltitle;

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

// invoke the preSave hook on pubfields
if (isset($pub['core_tid'])) {
$pubfields = Clip_Util::getPubFields($pub['core_tid']);

// TODO only modified fields check?
// FIXME move to a non-util method
Expand All @@ -414,9 +457,22 @@ public function preSave($event)
$plugin = Clip_Util_Plugins::get($field['fieldplugin']);

if (method_exists($plugin, 'preSave')) {
$obj[$fieldname] = $plugin->preSave($obj, $field);
$pub[$fieldname] = $plugin->preSave($pub, $field);
}
}
}
}

/**
* postSave hook.
*
* @return void
*/
public function postSave($event)
{
$pub = $event->getInvoker();

// update the meta values
$pub->clipValues();
}
}
6 changes: 2 additions & 4 deletions src/modules/Clip/workflows/operations/function.clone.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ function Clip_operation_clone(&$pub, $params)
// initializes the result flag
$result = false;

$tbl = Doctrine_Core::getTable('ClipModels_Pubdata'.$pub['core_tid']);

// finds the higher pid
$copy['core_pid'] = $tbl->selectFieldFunction('core_pid', 'MAX') + 1;
// utility vars
//$tbl = Doctrine_Core::getTable('ClipModels_Pubdata'.$pub['core_tid']);

// update any other parameter as that exists
foreach ($params as $key => $val) {
Expand Down
23 changes: 4 additions & 19 deletions src/modules/Clip/workflows/operations/function.create.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,17 @@ function Clip_operation_create(&$pub, $params)
$pub['core_online'] = isset($params['online']) ? (int)(bool)$params['online'] : 0;
$silent = isset($params['silent']) ? (bool)$params['silent'] : false;

// utility vars
$tablename = 'ClipModels_Pubdata'.$pub['core_tid'];

// initializes the result flag
$result = false;

// utility vars
$tbl = Doctrine_Core::getTable('ClipModels_Pubdata'.$pub['core_tid']);

// validate or find a new pid
if (isset($pub['core_pid']) && !empty($pub['core_pid'])) {
if (count(Doctrine_Core::getTable($tablename)->findBy('core_pid', $pub['core_pid']))) {
if (count($tbl->findBy('core_pid', $pub['core_pid']))) {
return LogUtil::registerError(__('Error! The fixed publication id already exists on the database. Please contact the administrator.', $dom));
}
} else {
$pub['core_pid'] = Doctrine_Core::getTable($tablename)->selectFieldFunction('core_pid', 'MAX') + 1;
}

// assign the author
$pub['core_author'] = (int)UserUtil::getVar('uid');

// assign the language
if (is_null($pub['core_language'])) {
$pub['core_language'] = '';
}

// fills the publish date automatically
if (empty($pub['core_publishdate'])) {
$pub['core_publishdate'] = DateUtil::getDatetime();
}

// save the object
Expand Down
1 change: 1 addition & 0 deletions src/modules/Clip/workflows/operations/function.delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function Clip_operation_delete(&$pub, $params)
// process the deletion
$result = false;

// utility vars
$pubtype = Clip_Util::getPubType($pub['core_tid']);

$workflow = new Clip_Workflow($pubtype, $pub);
Expand Down
1 change: 1 addition & 0 deletions src/modules/Clip/workflows/operations/function.notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function Clip_operation_notify(&$pub, $params)
$type = isset($params['type']) ? $params['type'] : 'update';
$template = isset($params['template']) ? $params['template'] : "{$group}_{$type}";

// utility vars
$pubtype = Clip_Util::getPubType($pub['core_tid']);

// create the View object
Expand Down
20 changes: 10 additions & 10 deletions src/modules/Clip/workflows/operations/function.update.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ function Clip_operation_update(&$pub, &$params)
// e.g. when the revision is pending (waiting state) and will be updated
$pubtype = Clip_Util::getPubType($pub['core_tid']);

if ($pubtype['enablerevisions'] && $pub['core_online'] == 1) {
// set all other to offline
$tbl->createQuery()
->update()
->set('core_online', 0)
->where('core_online = ?', 1)
->andWhere('core_pid = ?', $pub['core_pid'])
->execute();
}

// checks if there are fixed operation values to update
$update = array();
foreach ($params as $key => $val) {
Expand All @@ -69,6 +59,16 @@ function Clip_operation_update(&$pub, &$params)
$rev['core_revision'] = $maxrev + 1;

if ($rev->isValid()) {
if ($pub['core_online'] == 1) {
// set all other to offline
$tbl->createQuery()
->update()
->set('core_online', 0)
->where('core_online = ?', 1)
->andWhere('core_pid = ?', $pub['core_pid'])
->execute();
}

$rev->trySave();
$result = true;

Expand Down

0 comments on commit f19f50c

Please sign in to comment.