N°659 Console & Portal now we have same object save error messages and sessionmessages

* create new CoreCannotSaveException
* throw this exception in DBInsertNoReload/DBUpdate if CheckToWrite fails
* console : change UI.php code to catch this exception instead of calling CheckToWrite itself (was called twice :(( )
* portal : specific catch for the new exception
* portal : get and displays session messages
This commit is contained in:
Pierre Goiffon
2018-10-19 15:09:31 +02:00
parent 027b0fcff7
commit def4c54d26
8 changed files with 231 additions and 95 deletions

View File

@@ -19,29 +19,30 @@
namespace Combodo\iTop\Portal\Form;
use Exception;
use Silex\Application;
use utils;
use Dict;
use IssueLog;
use UserRights;
use MetaModel;
use CMDBSource;
use DBObject;
use DBObjectSet;
use DBSearch;
use DBObjectSearch;
use InlineImage;
use ormTagSet;
use AttachmentPlugIn;
use AttributeDateTime;
use AttributeTagSet;
use AttachmentPlugIn;
use Combodo\iTop\Form\FormManager;
use Combodo\iTop\Form\Form;
use CMDBSource;
use Combodo\iTop\Form\Field\Field;
use Combodo\iTop\Form\Field\FileUploadField;
use Combodo\iTop\Form\Field\LabelField;
use Combodo\iTop\Form\Form;
use Combodo\iTop\Form\FormManager;
use Combodo\iTop\Portal\Helper\ApplicationHelper;
use CoreCannotSaveObjectException;
use DBObject;
use DBObjectSearch;
use DBObjectSet;
use DBSearch;
use Dict;
use Exception;
use InlineImage;
use IssueLog;
use MetaModel;
use ormTagSet;
use Silex\Application;
use UserRights;
use utils;
/**
* Description of objectformmanager
@@ -976,7 +977,14 @@ class ObjectFormManager extends FormManager
// Writing object to DB
$bActivateTriggers = (!$this->oObject->IsNew() && $this->oObject->IsModified());
$bWasModified = $this->oObject->IsModified();
$this->oObject->DBWrite();
try
{
$this->oObject->DBWrite();
}
catch (CoreCannotSaveObjectException $e)
{
throw new Exception($e->getHtmlMessage());
}
// Finalizing images link to object, otherwise it will be cleaned by the GC
InlineImage::FinalizeInlineImages($this->oObject);
// Finalizing attachments link to object

View File

@@ -20,6 +20,7 @@
namespace Combodo\iTop\Portal\Helper;
use ApplicationContext;
use cmdbAbstractObject;
use Combodo\iTop\Portal\Brick\AbstractBrick;
use Combodo\iTop\Portal\Brick\PortalBrick;
use DBObjectSearch;
@@ -30,12 +31,10 @@ use Exception;
use iPortalUIExtension;
use IssueLog;
use MetaModel;
use cmdbAbstractObject;
use ModuleDesign;
use Silex\Application;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Twig_Environment;
use Twig_SimpleFilter;
@@ -1343,6 +1342,45 @@ class ApplicationHelper
return $aUIExtensions;
}
public static function LoadSessionMessages(Application $oApp)
{
$aAllMessages = array();
if ((array_key_exists('obj_messages', $_SESSION)) && (!empty($_SESSION['obj_messages'])))
{
foreach ($_SESSION['obj_messages'] as $sMessageKey => $aMessageObjectData)
{
$aObjectMessages = array();
$aRanks = array();
foreach ($aMessageObjectData as $sMessageId => $aMessageData)
{
$sMsgClass = 'alert alert-';
switch ($aMessageData['severity'])
{
case 'info':
$sMsgClass .= 'info';
break;
case 'error':
$sMsgClass .= 'danger';
break;
case 'ok':
default:
$sMsgClass .= 'success';
break;
}
$aObjectMessages[] = array('cssClass' => $sMsgClass, 'message' => $aMessageData['message']);
$aRanks[] = $aMessageData['rank'];
}
unset($_SESSION['obj_messages'][$sMessageKey]);
array_multisort($aRanks, $aObjectMessages);
foreach ($aObjectMessages as $aObjectMessage)
{
$aAllMessages[] = $aObjectMessage;
}
}
}
$oApp['combodo.current_user.session_messages'] = $aAllMessages;
}
/**
* Generate the form data for the $sClass.
* Form will look like the "Properties" tab of a $sClass object in the console.

View File

@@ -313,7 +313,17 @@
<div class="container-fluid" id="main-wrapper">
<div class="row">
<div class="col-xs-12 col-sm-9 col-md-10 col-sm-offset-3 col-md-offset-2">
{% if app['combodo.current_user.session_messages']|length > 0 %}
<section class="row" id="session-messages">
<div class="col-xs-12">
{% for sessionMessage in app['combodo.current_user.session_messages'] %}
<div class="{{ sessionMessage['cssClass'] }}">{{ sessionMessage['message'] }}</div>
{% endfor %}
</div>
</section>
{% endif %}
<section class="row" id="main-header">
{% block pMainHeader %}
{% endblock %}

View File

@@ -45,8 +45,8 @@ require_once __DIR__ . '/../src/helpers/lifecyclevalidatorhelper.class.inc.php';
require_once __DIR__ . '/../src/helpers/securityhelper.class.inc.php';
require_once __DIR__ . '/../src/helpers/applicationhelper.class.inc.php';
use Silex\Application;
use Combodo\iTop\Portal\Helper\ApplicationHelper;
use Silex\Application;
// Stacking context tag so it knows we are in the portal
$oContex = new ContextTag('GUI:Portal');
@@ -141,6 +141,7 @@ $oApp->before(function(Symfony\Component\HttpFoundation\Request $oRequest, Silex
// Loading portal configuration from the module design
$oKPI = new ExecutionKPI();
ApplicationHelper::LoadPortalConfiguration($oApp);
ApplicationHelper::LoadSessionMessages($oApp);
$oKPI->ComputeAndReport('Parsing portal configuration');
// Loading current user
ApplicationHelper::LoadCurrentUser($oApp);