Workflows #398

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@paustian
Contributor
paustian commented May 2, 2012

I added the code that I “think” will work for workflows. This is a noobie guess, especially the correct method of pointing to the table. I guessed it was Workflow\Entity\Workflow, but it could be different.

@paustian paustian Added the changes as I see them for workflow. I need to get 1.4 up an…
…d running and then be able to debug the code to make sure it does what it is supposed to.
0e4c0c4
Owner
craigh commented May 2, 2012

no entity? not even attempted to be tested?

Contributor
paustian commented May 3, 2012

Drak asked me to PR it, he knew the state it was in.

@ghost
ghost commented May 3, 2012

It might better if you create a topic branch - please see https://github.com/zikula/core/wiki/Contributor-Workflow (it would mean closing this PR, branching and opening a new on as per the instructions above).

While a PR is a "work in progress" also please prefix the title of the PR "[WIP]" so we know.

@ghost
ghost commented May 3, 2012

@craigh - the entities are already in the codebase - I added all required entities a couple of weeks back.

@ghost Unknown commented on the diff May 3, 2012
src/legacy/Zikula/Workflow/Util.php
// this is a cheat to delete all items in table with value $module
- return (bool)DBUtil::deleteObjectByID('workflows', $module, 'module');
+ //return (bool)DBUtil::deleteObjectByID('workflows', $module, 'module');
@ghost
ghost May 3, 2012

Please remove this comment.

craigh
craigh May 3, 2012 Owner

can be done with dql.

pseudo-code

$dql = 'DELETE from Workflow\Entity\Workflow WHERE module=:module';
->setParameter('workflow', $workflow);
@ghost Unknown commented on the diff May 3, 2012
src/legacy/Zikula/Workflow/Util.php
@@ -349,14 +366,21 @@ public static function getWorkflowForObject(&$obj, $dbTable, $idcolumn = 'id', $
if (!empty($obj[$idcolumn])) {
// get workflow data from DB
- $dbtables = DBUtil::getTables();
+ $dbtables = ServiceUtil::getManager()->getParameter('dbtables');
@ghost
ghost May 3, 2012

tables.php is going away so this doesn't belong in any D2 refactoring we will use entities straight.

@ghost Unknown commented on the diff May 3, 2012
src/legacy/Zikula/Workflow/Util.php
- AND $workflows_column[obj_id] = '" . DataUtil::formatForStore($obj[$idcolumn]) . "'";
-
- $workflow = DBUtil::selectObject('workflows', $where);
+ //This is a static function, so we have to user ServiceUtil to get the manager
+ $sm = ServiceUtil::getManager();
+ $entityManager = $sm->get('doctrine')->getEntityManager();
+ //prep the date for the table
+ $module = DataUtil::formatForStore($module);
+ $obj_table = DataUtil::formatForStore($dbTable);
+ $obj_idcolumn = DataUtil::formatForStore($idcolumn);
+ $obj_id = DataUtil::formatForStore($obj[$idcolumn]);
+ $workflow = $entityManager->findBy('Workflow\Entity\Workflow',
+ array('module' => $module,
+ 'obj_table' => $obj_table,
+ 'obj_idcolumn' => $obj_idcolumn,
+ 'obj_id' => $obj_id));
@ghost
ghost May 3, 2012

Field names are fixed, there is no need to do any lookup.

Owner
craigh commented May 3, 2012

you'll want to look into having a Repository class that can contain all your required dql commands.take a look at the example mods I mentioned.

@tfotis tfotis commented on the diff May 3, 2012
src/legacy/Zikula/Workflow/Util.php
@@ -185,9 +185,17 @@ public static function deleteWorkflowsForModule($module)
if (!isset($module)) {
$module = ModUtil::getName();
}
-
+ //This is a static function, so we have to user ServiceUtil to get the manager
+ $sm = ServiceUtil::getManager();
+ $entityManager = $sm->get('doctrine')->getEntityManager();
tfotis
tfotis May 3, 2012 Member

you can get entity manager with just a single line of code $em = \ServiceUtil::get('doctrine')->getManager();

@ghost
ghost May 8, 2012

I think it's ->get('doctrine')->getEntityManager();
It's different to 1.3's way as it's using DoctrineBundle.

@tfotis tfotis commented on the diff May 3, 2012
src/legacy/Zikula/Workflow/Util.php
@@ -185,9 +185,17 @@ public static function deleteWorkflowsForModule($module)
if (!isset($module)) {
$module = ModUtil::getName();
}
-
+ //This is a static function, so we have to user ServiceUtil to get the manager
+ $sm = ServiceUtil::getManager();
+ $entityManager = $sm->get('doctrine')->getEntityManager();
+ $workflow = $entityManager->findBy('Workflow\Entity\Workflow', array('module' => $module));
+ $entityManager->remove($workflow);
tfotis
tfotis May 3, 2012 Member

findBy returns an array of objects, so remove will not work here.
Either do findOneBy or loop through the returned objects.

@tfotis tfotis commented on the diff May 3, 2012
src/legacy/Zikula/Workflow/Util.php
@@ -185,9 +185,17 @@ public static function deleteWorkflowsForModule($module)
if (!isset($module)) {
$module = ModUtil::getName();
}
-
+ //This is a static function, so we have to user ServiceUtil to get the manager
+ $sm = ServiceUtil::getManager();
+ $entityManager = $sm->get('doctrine')->getEntityManager();
+ $workflow = $entityManager->findBy('Workflow\Entity\Workflow', array('module' => $module));
+ $entityManager->remove($workflow);
+ $entityManager->flush();
+ //Not sure what to return here. Or if there is some error checking that needs to be done.
+ return true;
tfotis
tfotis May 3, 2012 Member

return true is fine...if the above doctrine code fails, it will throw an Exception anyway.
you can cache that if you like but i think it isn't important at this stage of refactoring.

@ghost
ghost May 3, 2012

Caching would be doe by the entity manager in any case.

tfotis
tfotis May 3, 2012 Member

my bad, i meant catching not caching....

Contributor
paustian commented May 3, 2012

There are a bunch of issues with this branch and I didn't do it the standard way. I am gonna close this pull request and then resubmit it the right way once I have made some changes as suggested. Thanks for the help all. I will probably be out of commission for a bit. It's the end of the semester and I have papers to grade.

@paustian paustian closed this May 3, 2012
Owner
craigh commented May 3, 2012

college or k-12 teacher? (me too - I teach HS Band)

Contributor
paustian commented May 3, 2012

College at UW-Madison. I teach microbiology.

Owner
craigh commented May 4, 2012

ewwww. ;-)

@craigh craigh modified the milestone: 2.0.0, Discarded Tickets Feb 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment