Infolog - fix project would not stay set when set through the edit dialog pm_id field

This commit is contained in:
nathangray 2017-09-21 11:37:49 -06:00
parent 12bcc92f70
commit cc50ca5ea4
4 changed files with 73 additions and 33 deletions

View File

@ -494,6 +494,7 @@ class infolog_bo
$old_pm_id = is_array($pm_links) ? array_shift($pm_links) : $info['old_pm_id'];
if (!isset($info['pm_id']) && $old_pm_id) $info['pm_id'] = $old_pm_id;
return $old_pm_id;
}
/**
@ -978,7 +979,7 @@ class infolog_bo
Link::link('infolog',$info_id,$to_write['link_to']['to_id']);
$values['link_to']['to_id'] = $info_id;
}
$this->write_check_links($to_write);
$this->write_check_links($to_write);
if(!$values['info_link_id'] || $values['info_link_id'] != $to_write['info_link_id'])
{
// Just got a link ID, need to save it
@ -988,6 +989,7 @@ class infolog_bo
$values['info_from'] = $to_write['info_from'];
$this->link_id2from($values);
}
$values['pm_id'] = $to_write['pm_id'];
if (($info_from_set = ($values['info_link_id'] && isset($values['info_from']) && empty($values['info_from']))))
{
@ -1144,6 +1146,12 @@ class infolog_bo
$values['info_link_id'] = $link_id;
}
}
else
{
// Project removed, but primary link is not to project
Link::unlink(0,'infolog',$values['info_id'],0,'projectmanager',$values['old_pm_id']);
$values['pm_id'] = null;
}
}
if ($old_link_id && $old_link_id != $values['info_link_id'])
{

View File

@ -1787,32 +1787,9 @@ class infolog_ui
Framework::refresh_opener($content['msg'],'infolog',$info_id,$operation);
}
$content['tabs'] = $active_tab;
//try to keep the project manager link if the intenstion is only to remove contact
if ($old['info_link']['app'] == 'projectmanager' && $old['info_link']['id'] = $content['pm_id'])
{
Link::link('infolog',$content['link_to']['to_id'],'projectmanager',$content['pm_id']);
}
if ((int) $content['pm_id'] != (int) $content['old_pm_id'])
{
//echo "<p>pm_id changed: $content[old_pm_id] -> $content[pm_id]</p>\n";
// update links accordingly, if selected project changed
if ($content['pm_id'])
{
//echo "<p>this->link->link('infolog',{$content['link_to']['to_id']},'projectmanager',{$content['pm_id']});</p>";
Link::link('infolog',$info_id,'projectmanager',$content['pm_id']);
// making the project the selected link, if no other link selected
if (!$info_link_id || $info_link_id == 'projectmanager:'.$content['old_pm_id'])
{
$info_link_id = 'projectmanager:'.$content['pm_id'];
}
}
if ($content['old_pm_id'])
{
//echo "<p>this->link->unlink2(0,infolog,{$content['link_to']['to_id']},0,'projectmanager',{$content['old_pm_id']});</p>\n";
Link::unlink2(0,infolog,$content['link_to']['to_id'],0,'projectmanager',$content['old_pm_id']);
}
$content['old_pm_id'] = $content['pm_id'];
}
$pm_links = Link::get_links('infolog',$content['info_id'],'projectmanager');
$content['link_to']['to_app'] = 'infolog';
$content['link_to']['to_id'] = $info_id;
@ -2182,7 +2159,7 @@ class infolog_ui
$content['info_anz_subs'] = (int)$content['info_anz_subs']; // gives javascript error if empty!
$old_pm_id = is_array($pm_links) ? array_shift($pm_links) : $content['old_pm_id'];
if (!isset($content['pm_id']) && $old_pm_id) $content['pm_id'] = $old_pm_id;
unset($content['old_pm_id']);
if ($info_id && $this->bo->history)
{
@ -2256,14 +2233,15 @@ class infolog_ui
//echo "<p>infolog_ui.edit(info_id='$info_id',action='$action',action_id='$action_id') readonlys="; print_r($readonlys); echo ", content = "; _debug_array($content);
//$content['info_cc'] is expected (by the widget) to be an array of emailaddresses, but is stored as comma separated string
if (!empty($content['info_cc'])&&!is_array($content['info_cc']))$content['info_cc'] = explode(',',$content['info_cc']);
$this->tmpl->exec('infolog.infolog_ui.edit',$content,$sel_options,$readonlys,$preserv+array( // preserved values
$preserve = array_merge( $preserv, array( // preserved values
'info_id' => $info_id,
'action' => $action,
'action_id' => $action_id,
'referer' => $referer,
'no_popup' => $no_popup,
'old_pm_id' => $old_pm_id,
),$no_popup ? 0 : 2);
));
$this->tmpl->exec('infolog.infolog_ui.edit',$content,$sel_options,$readonlys,$preserve,$no_popup ? 0 : 2);
}
/**

View File

@ -56,6 +56,8 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest
if($this->info_id)
{
$this->bo->delete($this->info_id, False, False, True);
// One more time for history
$this->bo->delete($this->info_id, False, False, True);
}
// Remove the test project
@ -190,6 +192,57 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest
$this->checkElements();
}
/**
* Test adding a project to an infolog that has a contact (link to addressbook) set
*/
public function testLinkContact()
{
// Saving the infolog should try to send a notification
$this->bo->tracking->expects($this->once())
->method('track')
->with($this->callback(function($subject) { return $subject['pm_id'] == $this->pm_id;}));
$info = $this->getTestInfolog();
// Set up the test - just set info_contact
$info['info_contact'] = array(
'app' => 'addressbook',
// Linking to current user's contact
'id' => $GLOBALS['egw_info']['user']['person_id'],
);
// Set project by pm_id
$info['pm_id'] = $this->pm_id;
$this->info_id = $this->bo->write($info);
$this->assertArrayHasKey('info_id', $info, 'Could not make test entry');
$this->assertThat($this->info_id,
$this->logicalAnd(
$this->isType('integer'),
$this->greaterThan(0)
)
);
// Now load it again
$info = $this->bo->read($this->info_id);
// Check infolog still has pm_id
$this->assertEquals($this->pm_id, $info['pm_id'], 'Project went missing');
// Check that infolog still has contact
$this->assertArraySubset(
array('app' => 'addressbook', 'id' =>$GLOBALS['egw_info']['user']['person_id']),
$info['info_contact']
);
// Force links to run notification now so we get valid testing - it
// usually waits until Egw::on_shutdown();
Api\Link::run_notifies();
// Check project
$this->checkElements();
}
/**
* Test free text in the contact field
*/

View File

@ -106,7 +106,7 @@ class StatusTest extends \EGroupware\Api\AppTest
{
$info["info_{$field}"] = $value;
}
// Skipping notifications
$this->bo->write($info, true, true, true, true);
@ -120,11 +120,12 @@ class StatusTest extends \EGroupware\Api\AppTest
$this->assertEquals($value, $saved["info_{$field}"],
"$test_name failed on '$field' field");
}
// Remove infolog under test
if($this->info_id)
{
$this->bo->delete($this->info_id, False, False, True);
$this->bo->delete($this->info_id, False, False, True);
}
}
@ -172,7 +173,7 @@ class StatusTest extends \EGroupware\Api\AppTest
*/
public function testCustomStatus()
{
$this->checkOne(
array('status' => 'custom', 'percent' => 10),
array('status' => 'ongoing'),