mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 06:48:50 +02:00
Add operation on replica
This commit is contained in:
@@ -533,6 +533,11 @@ JS
|
||||
$sLabel = Dict::S('Tag:Synchronized');
|
||||
$sSynchroTagId = 'synchro_icon-'.$this->GetKey();
|
||||
$aTags[$sSynchroTagId] = ['title' => $sTip, 'css_classes' => 'ibo-object-details--tag--synchronized', 'decoration_classes' => 'fas fa-lock', 'label' => $sLabel];
|
||||
if (UserRights::IsActionAllowed('SynchroReplica', UR_ACTION_READ)) {
|
||||
$sFilter = 'SELECT SynchroReplica WHERE dest_class=\''.get_class($this).'\' AND dest_id='.$this->GetKey();
|
||||
$sUrlSearchReplica = 'UI.php?operation=search&filter='.urlencode(json_encode([$sFilter, [], []]));
|
||||
$oPage->add_ready_script("$('#$sSynchroTagId').on('click',function() {window.location = '$sUrlSearchReplica' });");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3082,13 +3082,17 @@ class AttributeObjectKey extends AttributeDBFieldVoid
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (MetaModel::IsValidObject($proposedValue))
|
||||
{
|
||||
if (MetaModel::IsValidObject($proposedValue)) {
|
||||
return $proposedValue->GetKey();
|
||||
}
|
||||
|
||||
return (int)$proposedValue;
|
||||
}
|
||||
|
||||
public function GetTargetClass($iType = EXTKEY_RELATIVE)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\WebPage\iTopWebPage;
|
||||
use Combodo\iTop\Core\CMDBChange\CMDBChangeOrigin;
|
||||
|
||||
require_once('../approot.inc.php');
|
||||
require_once(APPROOT.'/application/application.inc.php');
|
||||
|
||||
require_once(APPROOT.'/application/startup.inc.php');
|
||||
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
|
||||
LoginWebPage::DoLogin();
|
||||
LoginWebPage::DoLogin();
|
||||
|
||||
$sOperation = utils::ReadParam('operation', 'menu');
|
||||
$oAppContext = new ApplicationContext();
|
||||
@@ -33,46 +34,163 @@ $oP = new iTopWebPage("iTop - Synchro Replicas");
|
||||
|
||||
// Main program
|
||||
$sOperation = utils::ReadParam('operation', 'details');
|
||||
try
|
||||
|
||||
/**
|
||||
* @param \DBObject|null $oReplica
|
||||
* @param $this
|
||||
*
|
||||
* @return \SynchroLog
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreCannotSaveObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \CoreWarning
|
||||
* @throws \MySQLException
|
||||
* @throws \OQLException
|
||||
* @throws \SynchroExceptionNotStarted
|
||||
*/
|
||||
function Synchro($oReplica): SynchroLog
|
||||
{
|
||||
switch($sOperation)
|
||||
{
|
||||
$oDataSource = MetaModel::GetObject('SynchroDataSource', $oReplica->Get('sync_source_id'));
|
||||
|
||||
$oStatLog = new SynchroLog();
|
||||
$oStatLog->Set('sync_source_id', $oDataSource->GetKey());
|
||||
$oStatLog->Set('start_date', time());
|
||||
$oStatLog->Set('status', 'running');
|
||||
$oStatLog->AddTrace('Manual synchro');
|
||||
|
||||
// Get the list of SQL columns
|
||||
$aAttCodesExpected = array();
|
||||
$aAttCodesToReconcile = array();
|
||||
$aAttCodesToUpdate = array();
|
||||
$sSelectAtt = 'SELECT SynchroAttribute WHERE sync_source_id = :source_id AND (update = 1 OR reconcile = 1)';
|
||||
$oSetAtt = new DBObjectSet(DBObjectSearch::FromOQL($sSelectAtt), array() /* order by*/, array('source_id' => $oDataSource->GetKey()) /* aArgs */);
|
||||
while ($oSyncAtt = $oSetAtt->Fetch()) {
|
||||
if ($oSyncAtt->Get('update')) {
|
||||
$aAttCodesToUpdate[$oSyncAtt->Get('attcode')] = $oSyncAtt;
|
||||
}
|
||||
if ($oSyncAtt->Get('reconcile')) {
|
||||
$aAttCodesToReconcile[$oSyncAtt->Get('attcode')] = $oSyncAtt;
|
||||
}
|
||||
$aAttCodesExpected[$oSyncAtt->Get('attcode')] = $oSyncAtt;
|
||||
}
|
||||
|
||||
// Get the list of attributes, determine reconciliation keys and update targets
|
||||
//
|
||||
if ($oDataSource->Get('reconciliation_policy') == 'use_attributes') {
|
||||
$aReconciliationKeys = $aAttCodesToReconcile;
|
||||
} elseif ($oDataSource->Get('reconciliation_policy') == 'use_primary_key') {
|
||||
// Override the settings made at the attribute level !
|
||||
$aReconciliationKeys = array('primary_key' => null);
|
||||
}
|
||||
|
||||
if (count($aAttCodesToUpdate) == 0) {
|
||||
$oStatLog->AddTrace('No attribute to update');
|
||||
throw new SynchroExceptionNotStarted('There is no attribute to update');
|
||||
}
|
||||
if (count($aReconciliationKeys) == 0) {
|
||||
$oStatLog->AddTrace('No attribute for reconciliation');
|
||||
throw new SynchroExceptionNotStarted('No attribute for reconciliation');
|
||||
}
|
||||
|
||||
|
||||
$aAttributesToUpdate = array();
|
||||
foreach ($aAttCodesToUpdate as $sAttCode => $oSyncAtt) {
|
||||
$oAttDef = MetaModel::GetAttributeDef($oDataSource->GetTargetClass(), $sAttCode);
|
||||
if ($oAttDef->IsWritable()) {
|
||||
$aAttributesToUpdate[$sAttCode] = $oSyncAtt;
|
||||
}
|
||||
}
|
||||
// Create a change used for logging all the modifications/creations happening during the synchro
|
||||
$oChange = MetaModel::NewObject('CMDBChange');
|
||||
$oChange->Set('date', time());
|
||||
$sUserString = CMDBChange::GetCurrentUserName();
|
||||
$oChange->Set('userinfo', $sUserString.' '.Dict::S('Core:SyncDataExchangeComment'));
|
||||
$oChange->Set('origin', CMDBChangeOrigin::SYNCHRO_DATA_SOURCE);
|
||||
$oChange->DBInsert();
|
||||
CMDBObject::SetCurrentChange($oChange);
|
||||
|
||||
$oReplica->InitExtendedData($oDataSource);
|
||||
|
||||
$oReplica->Synchro($oDataSource, $aReconciliationKeys, $aAttributesToUpdate, $oChange, $oStatLog);
|
||||
$oReplica->DBUpdate();
|
||||
|
||||
return $oStatLog;
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($sOperation) {
|
||||
case 'details':
|
||||
$iId = utils::ReadParam('id', null);
|
||||
if ($iId == null)
|
||||
{
|
||||
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'id'));
|
||||
}
|
||||
$oReplica = MetaModel::GetObject('SynchroReplica', $iId);
|
||||
$oReplica->DisplayDetails($oP);
|
||||
break;
|
||||
|
||||
$iId = utils::ReadParam('id', null);
|
||||
if ($iId == null) {
|
||||
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'id'));
|
||||
}
|
||||
$oReplica = MetaModel::GetObject('SynchroReplica', $iId);
|
||||
$oReplica->DisplayDetails($oP);
|
||||
break;
|
||||
|
||||
case 'oql':
|
||||
$sOQL = utils::ReadParam('oql', null, false, 'raw_data');
|
||||
if ($sOQL == null)
|
||||
{
|
||||
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'oql'));
|
||||
}
|
||||
$oFilter = DBObjectSearch::FromOQL($sOQL);
|
||||
$sOQL = utils::ReadParam('oql', null, false, 'raw_data');
|
||||
if ($sOQL == null) {
|
||||
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'oql'));
|
||||
}
|
||||
$oFilter = DBObjectSearch::FromOQL($sOQL);
|
||||
$oBlock1 = new DisplayBlock($oFilter, 'search', false, array('menu' => false, 'table_id' => '1'));
|
||||
$oBlock1->Display($oP, 0);
|
||||
$oP->add('<p class="page-header">'.MetaModel::GetClassIcon('SynchroReplica').Dict::S('Core:SynchroReplica:ListOfReplicas').'</p>');
|
||||
$iSourceId = utils::ReadParam('datasource', null);
|
||||
if ($iSourceId != null)
|
||||
{
|
||||
$oSource = MetaModel::GetObject('SynchroDataSource', $iSourceId);
|
||||
$oP->p(Dict::Format('Core:SynchroReplica:BackToDataSource', $oSource->GetHyperlink()).'</a>');
|
||||
}
|
||||
$oBlock = new DisplayBlock($oFilter, 'list', false, array('menu'=>false));
|
||||
$oBlock->Display($oP, 1);
|
||||
break;
|
||||
$oBlock1->Display($oP, 0);
|
||||
$oP->add('<p class="page-header">'.MetaModel::GetClassIcon('SynchroReplica').Dict::S('Core:SynchroReplica:ListOfReplicas').'</p>');
|
||||
$iSourceId = utils::ReadParam('datasource', null);
|
||||
if ($iSourceId != null) {
|
||||
$oSource = MetaModel::GetObject('SynchroDataSource', $iSourceId);
|
||||
$oP->p(Dict::Format('Core:SynchroReplica:BackToDataSource', $oSource->GetHyperlink()).'</a>');
|
||||
}
|
||||
$oBlock = new DisplayBlock($oFilter, 'list', false, array('menu' => false));
|
||||
$oBlock->Display($oP, 1);
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
case 'select_for_deletion':
|
||||
// Redirect to the page that implements bulk delete
|
||||
$sDelete = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?'.$_SERVER['QUERY_STRING'];
|
||||
header("Location: $sDelete");
|
||||
break;
|
||||
// Redirect to the page that implements bulk delete
|
||||
$sDelete = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?'.$_SERVER['QUERY_STRING'];
|
||||
header("Location: $sDelete");
|
||||
break;
|
||||
|
||||
case 'unlinksynchro':
|
||||
$iId = utils::ReadParam('id', null);
|
||||
if ($iId == null) {
|
||||
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'id'));
|
||||
}
|
||||
$oReplica = MetaModel::GetObject('SynchroReplica', $iId);
|
||||
$oReplica->Set('dest_id', '');
|
||||
$oReplica->Set('status', 'new');
|
||||
$oReplica->DBWrite();
|
||||
|
||||
$oStatLog = Synchro($oReplica);
|
||||
$oP->add(implode('<br>', $oStatLog->GetTraces()));
|
||||
|
||||
$oReplica->DisplayDetails($oP);
|
||||
break;
|
||||
|
||||
case 'unlink':
|
||||
$iId = utils::ReadParam('id', null);
|
||||
if ($iId == null) {
|
||||
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'id'));
|
||||
}
|
||||
$oReplica = MetaModel::GetObject('SynchroReplica', $iId);
|
||||
$oReplica->Set('dest_id', '');
|
||||
$oReplica->Set('status', 'new');
|
||||
$oReplica->DBWrite();
|
||||
|
||||
$oReplica->DisplayDetails($oP);
|
||||
break;
|
||||
|
||||
case 'synchro':
|
||||
$iId = utils::ReadParam('id', null);
|
||||
if ($iId == null) {
|
||||
throw new ApplicationException(Dict::Format('UI:Error:1ParametersMissing', 'id'));
|
||||
}
|
||||
$oReplica = MetaModel::GetObject('SynchroReplica', $iId);
|
||||
$oStatLog = Synchro($oReplica);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(CoreException $e)
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Button\ButtonUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Title\TitleUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarUIBlockFactory;
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
|
||||
|
||||
class SynchroDataSource extends cmdbAbstractObject
|
||||
{
|
||||
@@ -2117,6 +2122,12 @@ class SynchroReplica extends DBObject implements iDisplay
|
||||
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
|
||||
}
|
||||
|
||||
public function InitExtendedData($oSource)
|
||||
{
|
||||
$sSQLTable = $oSource->GetDataTable();
|
||||
$this->m_aExtendedData = $this->LoadExtendedDataFromTable($sSQLTable);
|
||||
}
|
||||
|
||||
public function __construct($aRow = null, $sClassAlias = '', $aAttToLoad = null, $aExtendedDataSpec = null)
|
||||
{
|
||||
parent::__construct($aRow, $sClassAlias, $aAttToLoad, $aExtendedDataSpec);
|
||||
@@ -2759,13 +2770,102 @@ class SynchroReplica extends DBObject implements iDisplay
|
||||
function DisplayDetails(WebPage $oPage, $bEditMode = false)
|
||||
{
|
||||
// Object's details
|
||||
//$this->DisplayBareHeader($oPage, $bEditMode);
|
||||
$this->DisplayBareHeader($oPage, $bEditMode);
|
||||
|
||||
$oPage->AddTabContainer(OBJECT_PROPERTIES_TAB);
|
||||
$oPage->SetCurrentTabContainer(OBJECT_PROPERTIES_TAB);
|
||||
$oPage->SetCurrentTab('UI:PropertiesTab');
|
||||
$this->DisplayBareProperties($oPage, $bEditMode);
|
||||
}
|
||||
|
||||
public function DisplayBareHeader(WebPage $oPage, $bEditMode = false)
|
||||
{
|
||||
$oBlock = UIContentBlockUIBlockFactory::MakeStandard('title-for-replica', ['ibo-page-header--replica-title']);
|
||||
$oPage->AddSubBlock($oBlock);
|
||||
$oPage->add_style('.ibo-page-header--replica-title{ display: table; width: 100%;}');
|
||||
$oPage->add_style('.ibo-page-header--replica-title>.ibo-toolbar--button{ display: table-cell; vertical-align:middle;}');
|
||||
|
||||
$sId = $this->GetKey();
|
||||
$oTitle = TitleUIBlockFactory::MakeNeutral(Dict::S('Class:SynchroReplica'));
|
||||
$oBlock->AddSubBlock($oTitle);
|
||||
$oActionsToolbar = ToolbarUIBlockFactory::MakeForButton(MenuBlock::ACTIONS_TOOLBAR_ID_PREFIX.$sId);
|
||||
$oActionsToolbar->AddCSSClass('ibo-panel--toolbar');
|
||||
$oBlock->AddSubBlock($oActionsToolbar);
|
||||
|
||||
$sClass = get_class($this);
|
||||
$sRootUrl = utils::GetAbsoluteUrlAppRoot();
|
||||
$sUIPage = cmdbAbstractObject::ComputeStandardUIPage($sClass);
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sContext = $oAppContext->GetForLink();
|
||||
if (utils::IsNotNullOrEmptyString($sContext)) {
|
||||
$sContext = '&'.$sContext;
|
||||
}
|
||||
|
||||
$aActions = [];
|
||||
//Delete
|
||||
if (UserRights::IsActionAllowed($sClass, UR_ACTION_DELETE)) {
|
||||
$aActions['UI:Menu:Delete'] = array(
|
||||
'label' => Dict::S('UI:Menu:Delete'),
|
||||
'url' => "{$sRootUrl}pages/$sUIPage?operation=delete&class=$sClass&id=$sId{$sContext}",
|
||||
);
|
||||
}
|
||||
|
||||
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY)) {
|
||||
if (count($aActions) > 0) {
|
||||
$sSeparator = '<hr class="menu-separator"/>';
|
||||
$aActions['sep_0'] = array('label' => $sSeparator, 'url' => '');
|
||||
}
|
||||
$sUrl = "{$sRootUrl}synchro/replica.php?operation=unlink&class=$sClass&id=$sId{$sContext}";
|
||||
$aActions['Class:SynchroReplica/Action:unlink'] = [
|
||||
'label' => Dict::S('Class:SynchroReplica/Action:unlink'),
|
||||
'url' => $sUrl,
|
||||
'tooltip' => Dict::S('Class:SynchroReplica/Action:unlink+'),
|
||||
];
|
||||
|
||||
$sUrl = "{$sRootUrl}synchro/replica.php?operation=unlinksynchro&class=$sClass&id=$sId{$sContext}";
|
||||
$aActions['Class:SynchroReplica/Action:unlinksynchro'] = [
|
||||
'label' => Dict::S('Class:SynchroReplica/Action:unlinksynchro'),
|
||||
'url' => $sUrl,
|
||||
'tooltip' => Dict::S('Class:SynchroReplica/Action:unlinksynchro+'),
|
||||
];
|
||||
|
||||
$sUrl = "{$sRootUrl}synchro/replica.php?operation=synchro&class=$sClass&id=$sId{$sContext}";
|
||||
$aActions['Class:SynchroReplica/Action:synchro'] = [
|
||||
'label' => Dict::S('Class:SynchroReplica/Action:synchro'),
|
||||
'url' => $sUrl,
|
||||
'tooltip' => Dict::S('Class:SynchroReplica/Action:synchro+'),
|
||||
];
|
||||
}
|
||||
if (count($aActions) > 0) {
|
||||
$sRegularActionsMenuTogglerId = "ibo-regular-actions-menu-toggler-{$sId}";
|
||||
$sRegularActionsPopoverMenuId = "ibo-regular-actions-popover-{$sId}";
|
||||
|
||||
$oActionButton = ButtonUIBlockFactory::MakeIconAction('fas fa-ellipsis-v', Dict::S('UI:Menu:Actions'), 'UI:Menu:Actions', '', false, $sRegularActionsMenuTogglerId)
|
||||
->AddCSSClasses(['ibo-action-button', 'ibo-regular-action-button']);
|
||||
|
||||
$oRegularActionsMenu = $oPage->GetPopoverMenu($sRegularActionsPopoverMenuId, $aActions)
|
||||
->SetTogglerJSSelector("#$sRegularActionsMenuTogglerId")
|
||||
->SetContainer(PopoverMenu::ENUM_CONTAINER_BODY);
|
||||
|
||||
$oActionsToolbar->AddSubBlock($oActionButton)
|
||||
->AddSubBlock($oRegularActionsMenu);
|
||||
|
||||
$oActionButton = ButtonUIBlockFactory::MakeIconLink('fas fa-search', Dict::Format('UI:SearchFor_Class', MetaModel::GetName($sClass)), "{$sRootUrl}pages/UI.php?operation=search_form&do_search=0&class=$sClass{$sContext}", '', 'UI:SearchFor_Class');
|
||||
$oActionButton->AddCSSClasses(['ibo-action-button', 'ibo-regular-action-button']);
|
||||
$oActionsToolbar->AddSubBlock($oActionButton);
|
||||
}
|
||||
|
||||
$sUrl = "{$sRootUrl}pages/$sUIPage?operation=display&class=$sClass&id=$sId{$sContext}";
|
||||
$oActionButton = ButtonUIBlockFactory::MakeAlternativeNeutral('', 'UI:Button:Refresh');
|
||||
$oActionButton->SetIconClass('fas fa-sync-alt')
|
||||
->SetOnClickJsCode('window.location.href=\''.$sUrl.'\'')
|
||||
->SetTooltip(Dict::S('UI:Button:Refresh'))
|
||||
->AddCSSClasses(['ibo-action-button', 'ibo-regular-action-button']);
|
||||
$oActionsToolbar->AddSubBlock($oActionButton);
|
||||
|
||||
return $oBlock;
|
||||
}
|
||||
|
||||
function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array())
|
||||
{
|
||||
if ($bEditMode) {
|
||||
|
||||
Reference in New Issue
Block a user