1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

Closes #4745 - check for xml/install.xml during plugin installation.

This commit is contained in:
Cameron 2022-04-04 18:30:33 -07:00
parent 412b0b2efe
commit ba82fec626
2 changed files with 58 additions and 5 deletions

View File

@ -3115,6 +3115,18 @@ class e107plugin
} }
}*/ }*/
$xmlInstallStatus = $this->XmlInstallXml($function, $plug_vars['folder']);
if($xmlInstallStatus)
{
e107::getMessage()->addDebug("Default content added to table(s).");
}
elseif($xmlInstallStatus === false)
{
e107::getMessage()->addDebug("Failed to add content to table(s).");
}
// Run custom {plugin}_setup install/upgrade etc. for INSERT, ALTER etc. etc. etc. // Run custom {plugin}_setup install/upgrade etc. for INSERT, ALTER etc. etc. etc.
// Call any custom post functions defined in <plugin>_setup.php or the deprecated <management> section // Call any custom post functions defined in <plugin>_setup.php or the deprecated <management> section
if (!$this->execute_function($plug['plugin_path'], $function, 'post')) if (!$this->execute_function($plug['plugin_path'], $function, 'post'))
@ -3140,6 +3152,41 @@ class e107plugin
} }
/**
* Check for /xml/install.xml file and import database content only.
* @param string $function
* @param string $folder
* @return bool|null
*/
function XmlInstallXml($function, $folder)
{
if($function !== 'install')
{
return null;
}
$this->log("Running ".__FUNCTION__);
$path = e_PLUGIN.$folder.'/xml/install.xml';
if(!file_exists($path))
{
$this->log("No xml/install.xml file found.");
return null;
}
$ret = e107::getXml()->e107Import($path, 'install');
if(!empty($ret['success']))
{
return true;
}
return false;
}
/** /**
* @param $plug_vars * @param $plug_vars

View File

@ -1271,7 +1271,7 @@ class xmlClass
{ {
e107::getPlugConfig($type)->setPref($pArray); e107::getPlugConfig($type)->setPref($pArray);
} }
else // 'add' only new prefs elseif($mode === 'add') // 'add' only new prefs
{ {
foreach ($pArray as $pname => $pval) foreach ($pArray as $pname => $pval)
{ {
@ -1301,7 +1301,7 @@ class xmlClass
{ {
e107::getThemeConfig($type)->setPref($pArray); e107::getThemeConfig($type)->setPref($pArray);
} }
else // 'add' only new prefs elseif($mode === 'add') // 'add' only new prefs
{ {
foreach ($pArray as $pname => $pval) foreach ($pArray as $pname => $pval)
{ {
@ -1322,15 +1322,21 @@ class xmlClass
if(!empty($xmlArray['database'])) if(!empty($xmlArray['database']))
{ {
foreach($xmlArray['database']['dbTable'] as $val) foreach($xmlArray['database']['dbTable'] as $val)
{ {
$table = $val['@attributes']['name']; $table = $val['@attributes']['name'];
if(!isset($val['item'])) if(!isset($val['item']))
{ {
continue; continue;
} }
if($mode === 'install' && !$sql->isEmpty($table)) // install mode - ignore import when table contains data.
{
continue;
}
foreach($val['item'] as $item) foreach($val['item'] as $item)
{ {
$insert_array = array(); $insert_array = array();
@ -1342,11 +1348,11 @@ class xmlClass
$insert_array[$fieldkey] = $fieldval; $insert_array[$fieldkey] = $fieldval;
} }
if(($mode === "replace") && $sql->replace($table, $insert_array)!==FALSE) if(($mode === "replace") && $sql->replace($table, $insert_array)!==false)
{ {
$ret['success'][] = $table; $ret['success'][] = $table;
} }
elseif(($mode == "add") && $sql->insert($table, $insert_array)!==FALSE) elseif($sql->insert($table, $insert_array)!==false)
{ {
$ret['success'][] = $table; $ret['success'][] = $table;
} }