Skip to content

Commit

Permalink
fixes #685 - Add Workflow Management Implementation to pimcore - adde…
Browse files Browse the repository at this point in the history
…d workflowid to workflow state model
  • Loading branch information
cfasching committed Jun 23, 2016
1 parent f155f6c commit 48018d2
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
3 changes: 3 additions & 0 deletions pimcore/lib/Pimcore/WorkflowManagement/Workflow.php
Expand Up @@ -103,6 +103,9 @@ public function __construct($data)
$this->allowUnpublished = $data['allowUnpublished'];
}

public function getId() {
return $this->id;
}

/**
* Returns the default state for new elements
Expand Down
3 changes: 2 additions & 1 deletion pimcore/lib/Pimcore/WorkflowManagement/Workflow/Manager.php
Expand Up @@ -133,11 +133,12 @@ public function getUser()
*/
public function getWorkflowStateForElement() {
$elementType = Service::getElementType($this->element);
$workflowState = WorkflowState::getByIdAndType($this->element->getId(), $elementType);
$workflowState = WorkflowState::getByPrimary($this->element->getId(), $elementType, $this->workflow->getId());
if(empty($workflowState)) {
$workflowState = new WorkflowState();
$workflowState->setCid($this->element->getId());
$workflowState->setCtype($elementType);
$workflowState->setWorkflowId($this->workflow->getId());
}

return $workflowState;
Expand Down
Expand Up @@ -148,7 +148,7 @@ public static function sendEmailNotification($users, $note)
$mail->addTo($user->getEmail(), $user->getName());
}

$element = Element\Service::getElementById($note->getCtype(), $note->getId());
$element = Element\Service::getElementById($note->getCtype(), $note->getCid());

$mail->setSubject("[pimcore] {$note->getTitle()}, {$element->getType()} [{$element->getId()}]");

Expand Down
24 changes: 22 additions & 2 deletions pimcore/models/Element/WorkflowState.php
Expand Up @@ -30,6 +30,10 @@ class WorkflowState extends Model\AbstractModel {
*/
public $ctype;

/**
* @var int
*/
public $workflowId;
/**
* @var string
*/
Expand All @@ -44,12 +48,13 @@ class WorkflowState extends Model\AbstractModel {
/**
* @param $cid
* @param $ctype
* @param $workflowId
* @return null|WorkflowState
*/
public static function getByIdAndType($cid, $ctype) {
public static function getByPrimary($cid, $ctype, $workflowId) {
try {
$workflowState = new self();
$workflowState->getDao()->getByIdAndType($cid, $ctype);
$workflowState->getDao()->getByPrimary($cid, $ctype, $workflowId);

return $workflowState;
} catch (\Exception $e) {
Expand Down Expand Up @@ -122,6 +127,21 @@ public function setStatus($status)
$this->status = $status;
}

/**
* @return int
*/
public function getWorkflowId()
{
return $this->workflowId;
}

/**
* @param int $workflowId
*/
public function setWorkflowId($workflowId)
{
$this->workflowId = $workflowId;
}


}
5 changes: 3 additions & 2 deletions pimcore/models/Element/WorkflowState/Dao.php
Expand Up @@ -27,11 +27,12 @@ class Dao extends Model\Dao\AbstractDao
/**
* @param $cid
* @param $ctype
* @param $workflowId
* @throws \Exception
*/
public function getByIdAndType($cid, $ctype)
public function getByPrimary($cid, $ctype, $workflowId)
{
$data = $this->db->fetchRow("SELECT * FROM element_workflow_state WHERE cid = ? AND ctype = ?", [$cid, $ctype]);
$data = $this->db->fetchRow("SELECT * FROM element_workflow_state WHERE cid = ? AND ctype = ? AND workflowId = ?", [$cid, $ctype, $workflowId]);

if (!$data["cid"]) {
throw new \Exception("WorkflowStatus item with cid " . $cid . " and ctype " . $ctype . " not found");
Expand Down
4 changes: 2 additions & 2 deletions pimcore/models/Element/WorkflowState/Listing/Dao.php
Expand Up @@ -28,11 +28,11 @@ class Dao extends Model\Listing\Dao\AbstractDao
*/
public function load()
{
$workflowStateData = $this->db->fetchAll("SELECT cid, ctype FROM element_workflow_state" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
$workflowStateData = $this->db->fetchAll("SELECT cid, ctype, workflowId FROM element_workflow_state" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());

$workflowStates = [];
foreach ($workflowStateData as $entry) {
if ($workflowState = Model\Element\WorkflowState::getByIdAndType($entry['cid'], $entry['ctype'])) {
if ($workflowState = Model\Element\WorkflowState::getByPrimary($entry['cid'], $entry['ctype'], $entry['workflowid'])) {
$workflowStates[] = $workflowState;
}
}
Expand Down
5 changes: 3 additions & 2 deletions pimcore/modules/install/mysql/install.sql
Expand Up @@ -881,7 +881,8 @@ DROP TABLE IF EXISTS `element_workflow_state`;
CREATE TABLE `element_workflow_state` (
`cid` int(10) NOT NULL DEFAULT '0',
`ctype` enum('document','asset','object') NOT NULL,
`workflowId` int(11) NOT NULL,
`state` varchar(255) DEFAULT NULL,
`status` varchar(255) DEFAULT NULL,
PRIMARY KEY (`cid`, `ctype`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
PRIMARY KEY (`cid`,`ctype`,`workflowId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3 changes: 2 additions & 1 deletion update/3874/postupdate.php
Expand Up @@ -5,8 +5,9 @@
CREATE TABLE `element_workflow_state` (
`cid` int(10) NOT NULL DEFAULT '0',
`ctype` enum('document','asset','object') NOT NULL,
`workflowId` int(11) NOT NULL,
`state` varchar(255) DEFAULT NULL,
`status` varchar(255) DEFAULT NULL,
PRIMARY KEY (`cid`, `ctype`)
PRIMARY KEY (`cid`,`ctype`,`workflowId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
;");

0 comments on commit 48018d2

Please sign in to comment.