Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2010-09-25 18:47:06 +0400
committerRobin Appelman <icewind1991@gmail.com>2010-09-28 23:59:06 +0400
commitafbc4f1fb3c8aa206bbb3e9714a76d64e47b61f6 (patch)
treebf864859db2aa4b54edd10af4d4d7bd747877f84 /inc
parent1b5a0bb31e9af496fd1bea3f20ec5c925f01a923 (diff)
automatically install databased of plugins
Diffstat (limited to 'inc')
-rw-r--r--inc/lib_plugin.php129
1 files changed, 119 insertions, 10 deletions
diff --git a/inc/lib_plugin.php b/inc/lib_plugin.php
index c846fe25603..906d7c625dc 100644
--- a/inc/lib_plugin.php
+++ b/inc/lib_plugin.php
@@ -49,6 +49,16 @@ class OC_PLUGIN{
}
}
}
+ //check for uninstalled db's
+ if(isset($data['install']) and isset($data['install']['database'])){
+ foreach($data['install']['database'] as $db){
+ if(!$data['install']['database_installed'][$db]){
+ self::installDB($id);
+ break;
+ }
+ }
+ }
+
foreach($data['runtime'] as $include){
include($SERVERROOT.'/plugins/'.$id.'/'.$include);
}
@@ -60,16 +70,19 @@ class OC_PLUGIN{
* Load all plugins that aren't blacklisted
*/
public static function loadPlugins() {
- global $SERVERROOT;
- $plugins = array();
- $blacklist=self::loadBlacklist();
- $fd = opendir($SERVERROOT . '/plugins');
- while ( false !== ($filename = readdir($fd)) ) {
- if ( $filename<>'.' AND $filename<>'..' AND ('.' != substr($filename, 0, 1)) AND array_search($filename,$blacklist)===false) {
- self::load($filename);
+ global $CONFIG_INSTALLED;
+ if($CONFIG_INSTALLED){
+ global $SERVERROOT;
+ $plugins = array();
+ $blacklist=self::loadBlacklist();
+ $fd = opendir($SERVERROOT . '/plugins');
+ while ( false !== ($filename = readdir($fd)) ) {
+ if ( $filename<>'.' AND $filename<>'..' AND ('.' != substr($filename, 0, 1)) AND array_search($filename,$blacklist)===false) {
+ self::load($filename);
+ }
}
+ closedir($fd);
}
- closedir($fd);
}
/**
@@ -138,9 +151,9 @@ class OC_PLUGIN{
}
/**
- ( Load data from the plugin.xml of a plugin, either identified by the plugin or the path of the plugin.xml file
+ * Load data from the plugin.xml of a plugin, either identified by the plugin or the path of the plugin.xml file
* @param string id
- *( @return array
+ * @return array
*/
public static function getPluginData($id){
global $SERVERROOT;
@@ -194,6 +207,7 @@ class OC_PLUGIN{
break;
case 'database':
$data['install']['database'][]=$child->textContent;
+ $data['install']['database_installed'][$child->textContent]=($child->hasAttribute('installed') and $child->getAttribute('installed')=='true')?true:false;
break;
}
}
@@ -220,6 +234,101 @@ class OC_PLUGIN{
}
return $data;
}
+
+
+ /**
+ * Save data to the plugin.xml of a plugin, either identified by the plugin or the path of the plugin.xml file
+ * @param string id
+ * @param array data the plugin data in the same structure as returned by getPluginData
+ * @return bool
+ */
+ public static function savePluginData($id,$data){
+ global $SERVERROOT;
+ if(is_file($id)){
+ $file=$id;
+ }
+ if(!is_dir($SERVERROOT.'/plugins/'.$id) or !is_file($SERVERROOT.'/plugins/'.$id.'/plugin.xml')){
+ return false;
+ }else{
+ $file=$SERVERROOT.'/plugins/'.$id.'/plugin.xml';
+ }
+ $plugin=new DOMDocument();
+ $pluginNode=$plugin->createElement('plugin');
+ $pluginNode->setAttribute('version',$data['version']);
+ $plugin->appendChild($pluginNode);
+ $info=$plugin->createElement('info');
+ foreach($data['info'] as $name=>$value){
+ $node=$plugin->createElement($name);
+ $node->appendChild($plugin->createTextNode($value));
+ $info->appendChild($node);
+ }
+ $pluginNode->appendChild($info);
+ if(isset($data['runtime'])){
+ $runtime=$plugin->createElement('runtime');
+ foreach($data['runtime'] as $include){
+ $node=$plugin->createElement('include');
+ $node->appendChild($plugin->createTextNode($include));
+ $runtime->appendChild($node);
+ }
+ $pluginNode->appendChild($runtime);
+ }
+ if(isset($data['install'])){
+ $install=$plugin->createElement('install');
+ foreach($data['install']['include'] as $include){
+ $node=$plugin->createElement('include');
+ $node->appendChild($plugin->createTextNode($include));
+ $install->appendChild($node);
+ }
+ foreach($data['install']['dialog'] as $dialog){
+ $node=$plugin->createElement('dialog');
+ $node->appendChild($plugin->createTextNode($dialog));
+ $install->appendChild($node);
+ }
+ foreach($data['install']['database'] as $database){
+ $node=$plugin->createElement('database');
+ $node->appendChild($plugin->createTextNode($database));
+ if($data['install']['database_installed'][$database]){
+ $node->setAttribute('installed','true');
+ }
+ $install->appendChild($node);
+ }
+ $pluginNode->appendChild($install);
+ }
+ if(isset($data['uninstall'])){
+ $uninstall=$plugin->createElement('uninstall');
+ foreach($data['uninstall']['include'] as $include){
+ $node=$plugin->createElement('include');
+ $node->appendChild($plugin->createTextNode($include));
+ $uninstall->appendChild($node);
+ }
+ foreach($data['uninstall']['dialog'] as $dialog){
+ $node=$plugin->createElement('dialog');
+ $node->appendChild($plugin->createTextNode($dialog));
+ $uninstall->appendChild($node);
+ }
+ $pluginNode->appendChild($uninstall);
+ }
+ $plugin->save($file);
+ }
+
+ /**
+ * install the databases of a plugin
+ * @param string id
+ * @return bool
+ */
+ public static function installDB($id){
+ global $SERVERROOT;
+ $data=OC_PLUGIN::getPluginData($id);
+ foreach($data['install']['database'] as $db){
+ if (!$data['install']['database_installed'][$db]){
+ $file=$SERVERROOT.'/plugins/'.$id.'/'.$db;
+ OC_DB::createDbFromStructure($file);
+ $data['install']['database_installed'][$db]=true;
+ }
+ }
+ self::savePluginData($id,$data);
+ return true;
+ }
}
?>