Skip to content

Commit

Permalink
#2615 Wiki: delete filkes when block is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Trofimov committed Dec 23, 2021
1 parent 802fc09 commit d95c6be
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion inc/classes/BxDolStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ protected function isAllowedDeniedExt ($sExt, $sExtMode)
return in_array ($sExt, $this->_aObject[$sExtMode]);
}

protected function queueFiles($aFiles)
public function queueFiles($aFiles)
{
if (!$aFiles)
return 0;
Expand Down
23 changes: 22 additions & 1 deletion inc/classes/BxDolWiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ static public function getObjectInstance($sObject, $oTemplate = false)
return ($GLOBALS['bxDolClasses']['BxDolWiki!'.$sObject] = $o);
}

static public function onModuleUninstall($sModule)
{
$aBlockIds = BxDolWikiQuery::getWikiBlocks ($sModule);
if ($aBlockIds && is_array($aBlockIds))
self::onBlockDelete($aBlockIds);
}

static public function onBlockDelete($mixedBlockIds)
{
BxDolWikiQuery::deleteAllRevisions($mixedBlockIds);

$aBlockIds = is_array($mixedBlockIds) ? $mixedBlockIds : [$mixedBlockIds];
$oStorage = BxDolStorage::getObjectInstance('sys_wiki_files');
if ($oStorage) {
foreach ($aBlockIds as $iBlockId) {
$aFiles = $oStorage->getGhosts(0, $iBlockId, false, true);
$oStorage->queueFiles($aFiles);
}
}
}

/**
* Get object name
*/
Expand Down Expand Up @@ -571,7 +592,7 @@ public function actionDeleteBlock ()
if (!$oQueryPageBuilder->deleteBlocks(array('type' => 'by_id', 'value' => $iBlockId)))
return array('code' => 3, 'actions' => array('ShowMsg'), 'block_id' => $iBlockId, 'msg' => _t('_sys_wiki_error_occured', 3));

$this->_oQuery->deleteAllRevisions($iBlockId);
self::onBlockDelete($iBlockId);

return array('code' => 0, 'actions' => array('DeleteBlock', 'ShowMsg'), 'block_id' => $iBlockId, 'msg' => _t('_sys_wiki_block_deleted'));
}
Expand Down
6 changes: 6 additions & 0 deletions inc/classes/BxDolWikiQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public function __construct($aObject)
$this->_aObject = $aObject;
}

static public function getWikiBlocks ($sModule)
{
$oDb = BxDolDb::getInstance();
return $oDb->getColumn("SELECT `id` FROM `sys_pages_blocks` WHERE `module` = :module", ['module' => $sModule]);
}

static public function getWikiObjectByUri ($sUri)
{
return self::getWikiObjectByField ('uri', $sUri);
Expand Down
6 changes: 6 additions & 0 deletions modules/boonex/wiki/install/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ function __construct($aConfig)
{
parent::__construct($aConfig);
}

public function uninstall($aParams, $bAutoDisable = false)
{
BxDolWiki::onModuleUninstall($this->_aConfig['name']);
return parent::uninstall($aParams, $bAutoDisable);
}
}

/** @} */
2 changes: 2 additions & 0 deletions modules/boonex/wiki/install/sql/uninstall.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ DELETE FROM `wb`, `wc`
USING `sys_pages_blocks` AS `wb`, `sys_pages_wiki_blocks` AS `wc`
WHERE `wb`.`id` = `wc`.`block_id` AND `wb`.`module` = 'bx_wiki';

DELETE FROM `sys_pages_blocks` WHERE `module` = 'bx_wiki';

-- Studio page and widget

DELETE FROM `tp`, `tw`, `twb`, `tpw`
Expand Down
2 changes: 1 addition & 1 deletion studio/classes/BxDolStudioBuilderPageQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ function deleteBlocks($aParams)
$sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
$b = ((int)$this->query($sSql, $aBindings) > 0);
if ($b && $aBlockIds)
BxDolWikiQuery::deleteAllRevisions($aBlockIds);
BxDolWiki::onBlockDelete($aBlockIds);
return $b;
}

Expand Down

0 comments on commit d95c6be

Please sign in to comment.