diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index b74c46ffd..8ba8353d8 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -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. // Call any custom post functions defined in _setup.php or the deprecated section 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 diff --git a/e107_handlers/xml_class.php b/e107_handlers/xml_class.php index c97bf2fda..16adeb0f2 100644 --- a/e107_handlers/xml_class.php +++ b/e107_handlers/xml_class.php @@ -1271,7 +1271,7 @@ class xmlClass { e107::getPlugConfig($type)->setPref($pArray); } - else // 'add' only new prefs + elseif($mode === 'add') // 'add' only new prefs { foreach ($pArray as $pname => $pval) { @@ -1301,7 +1301,7 @@ class xmlClass { e107::getThemeConfig($type)->setPref($pArray); } - else // 'add' only new prefs + elseif($mode === 'add') // 'add' only new prefs { foreach ($pArray as $pname => $pval) { @@ -1322,15 +1322,21 @@ class xmlClass if(!empty($xmlArray['database'])) { + foreach($xmlArray['database']['dbTable'] as $val) { $table = $val['@attributes']['name']; - + if(!isset($val['item'])) { continue; } + if($mode === 'install' && !$sql->isEmpty($table)) // install mode - ignore import when table contains data. + { + continue; + } + foreach($val['item'] as $item) { $insert_array = array(); @@ -1342,11 +1348,11 @@ class xmlClass $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; } - elseif(($mode == "add") && $sql->insert($table, $insert_array)!==FALSE) + elseif($sql->insert($table, $insert_array)!==false) { $ret['success'][] = $table; }