/** * 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; }
private function read_snippetdir($snippetdir, $path) { $snippetdir_path = "{$path}{$snippetdir->name}"; if (!file_exists($snippetdir_path)) { mkdir($snippetdir_path); } $filenames = array(); $foldernames = array(); $snippet_qb = midcom_db_snippet::new_query_builder(); $snippet_qb->add_constraint('up', '=', $snippetdir->id); $snippets = $snippet_qb->execute(); foreach ($snippets as $snippet) { file_put_contents("{$snippetdir_path}/{$snippet->name}.php", $snippet->code); $filenames[] = "{$snippet->name}.php"; if (!empty($snippet->doc)) { file_put_contents("{$snippetdir_path}/{$snippet->name}.txt", $snippet->doc); $filenames[] = "{$snippet->name}.txt"; } } $dir_qb = midcom_db_snippetdir::new_query_builder(); $dir_qb->add_constraint('up', '=', $snippetdir->id); $dirs = $dir_qb->execute(); foreach ($dirs as $dir) { $this->read_snippetdir($dir, "{$snippetdir_path}/"); $foldernames[] = $dir->name; } if ($this->delete_missing) { // Then delete files and folders that are in DB but not in the importing folder $this->delete_missing_folders($foldernames, $style_path); $this->delete_missing_files($filenames, $style_path); } }
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(); }
private function delete_missing_files($filenames, $snippetdir_id) { if (!$this->delete_missing) { return; } $qb = midcom_db_snippet::new_query_builder(); $qb->add_constraint('up', '=', $snippetdir_id); if (!empty($filenames)) { $qb->add_constraint('name', 'NOT IN', $filenames); } $files = $qb->execute(); foreach ($files as $file) { $file->delete(); } }
/** * 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(); }