Example #1
0
 public function export()
 {
     $qb = midcom_db_snippetdir::new_query_builder();
     $qb->add_constraint('up', '=', 0);
     $rootdirs = $qb->execute();
     foreach ($rootdirs as $rootdir) {
         if ($rootdir->can_do('midgard:update')) {
             $this->read_snippetdir($rootdir, $this->root_dir);
         }
     }
 }
Example #2
0
 private function _save_configuration()
 {
     $sg_snippetdir = new midcom_db_snippetdir();
     $sg_snippetdir->get_by_path($GLOBALS['midcom_config']['midcom_sgconfig_basedir']);
     if ($sg_snippetdir->id == false) {
         $sd = new midcom_db_snippetdir();
         $sd->up = 0;
         $sd->name = $GLOBALS['midcom_config']['midcom_sgconfig_basedir'];
         if (!$sd->create()) {
             throw new midcom_error("Failed to create {$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}" . midcom_connection::get_error_string());
         }
         $sg_snippetdir = new midcom_db_snippetdir($sd->guid);
         unset($sd);
     }
     $lib_snippetdir = new midcom_db_snippetdir();
     $lib_snippetdir->get_by_path($GLOBALS['midcom_config']['midcom_sgconfig_basedir'] . "/" . $this->_component_name);
     if ($lib_snippetdir->id == false) {
         $sd = new midcom_db_snippetdir();
         $sd->up = $sg_snippetdir->id;
         $sd->name = $this->_component_name;
         if (!$sd->create()) {
             throw new midcom_error("Failed to create {$this->_component_name}" . midcom_connection::get_error_string());
         }
         $lib_snippetdir = new midcom_db_snippetdir($sd->guid);
         unset($sd);
     }
     $snippet = new midcom_db_snippet();
     $snippet->get_by_path($GLOBALS['midcom_config']['midcom_sgconfig_basedir'] . "/" . $this->_component_name . "/config");
     if ($snippet->id == false) {
         $sn = new midcom_db_snippet();
         $sn->up = $lib_snippetdir->id;
         $sn->name = "config";
         if (!$sn->create()) {
             throw new midcom_error("Failed to create config snippet" . midcom_connection::get_error_string());
         }
         $snippet = new midcom_db_snippet($sn->id);
     }
     $snippet->code = $this->_get_config($this->_controller);
     if ($snippet->code == '' || !$snippet->code) {
         throw new midcom_error("code-init content generation failed.");
     }
     return $snippet->update();
 }
Example #3
0
 /**
  * Save the configuration to the config snippet
  */
 private function load_snippet()
 {
     midcom::get('auth')->request_sudo('org.openpsa.core');
     $lib_snippetdir = new midcom_db_snippetdir();
     $lib_snippetdir->get_by_path("/org.openpsa.cache");
     if (!$lib_snippetdir->guid) {
         $sd = new midcom_db_snippetdir();
         $sd->name = 'org.openpsa.cache';
         if (!$sd->create()) {
             throw new midcom_error("Failed to create snippetdir /org.openpsa.cache: " . midcom_connection::get_error_string());
         }
         $lib_snippetdir = new midcom_db_snippetdir($sd->guid);
     }
     $this->snippet = new midcom_db_snippet();
     $this->snippet->get_by_path("/org.openpsa.cache/siteconfig");
     if ($this->snippet->id == false) {
         $this->snippet = new midcom_db_snippet();
         $this->snippet->up = $lib_snippetdir->id;
         $this->snippet->name = 'siteconfig';
         $this->snippet->code = "//AUTO-GENERATED BY org_openpsa_core_siteconfig\n";
         $this->snippet->create();
         $this->initialize_site_structure();
     }
     midcom::get('auth')->drop_sudo();
     eval("\$array = array ( {$this->snippet->code}\n );");
     $this->data = $array;
 }
Example #4
0
 private function delete_missing_folders($foldernames, $snippetdir_id)
 {
     if (!$this->delete_missing) {
         return;
     }
     $qb = midcom_db_snippetdir::new_query_builder();
     $qb->add_constraint('up', '=', $snippetdir_id);
     if (!empty($foldernames)) {
         $qb->add_constraint('name', 'NOT IN', $foldernames);
     }
     $folders = $qb->execute();
     foreach ($folders as $folder) {
         $folder->delete();
     }
 }
Example #5
0
 /**
  * Save configuration values to a topic as "serialized" array
  *
  * @return boolean
  */
 private function _save_snippet($config)
 {
     $sg_snippetdir = new midcom_db_snippetdir();
     $sg_snippetdir->get_by_path($GLOBALS['midcom_config']['midcom_sgconfig_basedir']);
     if (!$sg_snippetdir->guid) {
         // Create SG config snippetdir
         $sd = new midcom_db_snippetdir();
         $sd->up = 0;
         $sd->name = $GLOBALS['midcom_config']['midcom_sgconfig_basedir'];
         // remove leading slash from name
         $sd->name = preg_replace("/^\\//", "", $sd->name);
         if (!$sd->create()) {
             throw new midcom_error("Failed to create snippetdir {$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}: " . midcom_connection::get_error_string());
         }
         $sg_snippetdir = new midcom_db_snippetdir($sd->guid);
     }
     $lib_snippetdir = new midcom_db_snippetdir();
     $lib_snippetdir->get_by_path("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$this->_request_data['name']}");
     if (!$lib_snippetdir->guid) {
         $sd = new midcom_db_snippetdir();
         $sd->up = $sg_snippetdir->id;
         $sd->name = $this->_request_data['name'];
         if (!$sd->create()) {
             throw new midcom_error("Failed to create snippetdir {$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$data['name']}: " . midcom_connection::get_error_string());
         }
         $lib_snippetdir = new midcom_db_snippetdir($sd->guid);
     }
     $snippet = new midcom_db_snippet();
     $snippet->get_by_path("{$GLOBALS['midcom_config']['midcom_sgconfig_basedir']}/{$this->_request_data['name']}/config");
     if ($snippet->id == false) {
         $sn = new midcom_db_snippet();
         $sn->up = $lib_snippetdir->id;
         $sn->name = 'config';
         $sn->code = $config;
         return $sn->create();
     }
     $snippet->code = $config;
     return $snippet->update();
 }