public static function install($data, &$fail, &$errno, &$error) { $res = array(); if (!$fail) { // die /platform Befehle auslösen $list = Einstellungen::getLinks('postPlatform'); $platform = Installation::PlattformZusammenstellen($data); $multiRequestHandle = new Request_MultiRequest(); for ($i = 0; $i < count($list); $i++) { // inits all components $handler = Request_CreateRequest::createPost($list[$i]->getAddress() . '/platform', array(), Platform::encodePlatform($platform)); $multiRequestHandle->addRequest($handler); } $answer = $multiRequestHandle->run(); for ($i = 0; $i < count($list); $i++) { $url = $list[$i]->getTargetName(); $result = $answer[$i]; $res[$url] = array(); if (isset($result['content']) && isset($result['status']) && $result['status'] === 201) { $res[$url]['status'] = 201; } else { $res[$url]['status'] = 409; $fail = true; if (isset($result['status'])) { $errno = $result['status']; $res[$url]['status'] = $result['status']; } } } } return $res; }
/** * Adds the component to the platform * * Called when this component receives an HTTP POST request to * /platform. */ public function addPlatform() { Logger::Log('starts POST AddPlatform', LogLevel::DEBUG); // decode the received course data, as an object $insert = Platform::decodePlatform($this->_app->request->getBody()); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { // starts a query, by using a given file $result = DBRequest::getRoutedSqlFile($this->query2, dirname(__FILE__) . '/Sql/AddPlatform.sql', array('object' => $in), false); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $queryResult = Query::decodeQuery($result['content']); $res[] = $in; $this->_app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { Logger::Log('POST AddPlatform failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->_app->response->setBody(Platform::encodePlatform($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Platform::encodePlatform($res[0])); } else { $this->_app->response->setBody(Platform::encodePlatform($res)); } }
/** * Adds the component to the platform * * Called when this component receives an HTTP POST request to * /platform. */ public function addPlatform() { Logger::Log('starts POST AddPlatform', LogLevel::DEBUG); // decode the received course data, as an object $insert = Platform::decodePlatform($this->_app->request->getBody()); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { $file = dirname(__FILE__) . '/config.ini'; $text = "[DB]\n" . "db_path = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getDatabaseUrl()) . "\"\n" . "db_user = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getDatabaseOperatorUser()) . "\"\n" . "db_passwd = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getDatabaseOperatorPassword()) . "\"\n" . "db_name = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getDatabaseName()) . "\"\n" . "[PL]\n" . "urlExtern = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getExternalUrl()) . "\"\n" . "url = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), $in->getBaseUrl()) . "\""; if (!@file_put_contents($file, $text)) { Logger::Log('POST AddPlatform failed, config.ini no access', LogLevel::ERROR); $this->_app->response->setStatus(409); $this->_app->stop(); } // starts a query ob_start(); eval("?>" . file_get_contents(dirname(__FILE__) . '/Sql/AddPlatform.sql')); $sql = ob_get_contents(); ob_end_clean(); $result = DBRequest::request2($sql, false, parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE)); // checks the correctness of the query if (!isset($result['errno']) || !$result['errno']) { $platform = new Platform(); $platform->setStatus(201); $res[] = $platform; $this->_app->response->setStatus(201); } else { Logger::Log('POST AddPlatform failed', LogLevel::ERROR); $this->_app->response->setStatus(409); $this->_app->response->setBody(Platform::encodePlatform($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Platform::encodePlatform($res[0])); } else { $this->_app->response->setBody(Platform::encodePlatform($res)); } }
public static function install($data, &$fail, &$errno, &$error) { // Datenbank einrichten if (!isset($data['action']) || $data['action'] != 'update') { if (!$fail && (isset($data['DB']['db_override']) && $data['DB']['db_override'] === 'override')) { $sql = "DROP SCHEMA IF EXISTS `" . $data['DB']['db_name'] . "`;"; $oldName = $data['DB']['db_name']; $data['DB']['db_name'] = null; $result = DBRequest::request($sql, false, $data); if ($result["errno"] !== 0) { $fail = true; $errno = $result["errno"]; $error = isset($result["error"]) ? $result["error"] : ''; } $data['DB']['db_name'] = $oldName; } } if (!$fail) { $add = isset($data['DB']['db_ignore']) && $data['DB']['db_ignore'] === 'ignore' || isset($data['action']) && $data['action'] == 'update' ? 'IF NOT EXISTS ' : ''; $sql = "CREATE SCHEMA {$add}`" . $data['DB']['db_name'] . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;"; $oldName = $data['DB']['db_name']; $data['DB']['db_name'] = null; $result = DBRequest::request($sql, false, $data); if ($result["errno"] !== 0) { $fail = true; $errno = $result["errno"]; $error = isset($result["error"]) ? $result["error"] : ''; } $data['DB']['db_name'] = $oldName; } // CControl+DBQuery2 einrichten $res = array(); if (!$fail) { $list = array('DB/CControl', 'DB/DBQuery2'); $platform = Installation::PlattformZusammenstellen($data); for ($i = 0; $i < count($list); $i++) { $url = $list[$i]; //$data['PL']['init']; // inits all components $result = Request::post($data['PL']['url'] . '/' . $url . '/platform', array(), Platform::encodePlatform($platform)); $res[$url] = array(); if (isset($result['content']) && isset($result['status']) && $result['status'] === 201) { $res[$url]['status'] = 201; } else { $res[$url]['status'] = 409; $fail = true; if (isset($result['status'])) { $errno = $result['status']; $res[$url]['status'] = $result['status']; } ///if (isset($result['content'])) echo $result['content']; } } } return $res; }
/** * Adds the component to the platform * * Called when this component receives an HTTP POST request to * /platform. */ public function addPlatform() { Logger::Log('starts POST AddPlatform', LogLevel::DEBUG); // decode the received course data, as an object $insert = Platform::decodePlatform($this->app->request->getBody()); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { $file = dirname(__FILE__) . '/config.ini'; $text = "[DIR]\n" . "temp = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), str_replace("\\", "/", $in->getTempDirectory())) . "\"\n" . "files = \"" . str_replace(array("\\", "\""), array("\\\\", "\\\""), str_replace("\\", "/", $in->getFilesDirectory())) . "\"\n"; if (!@file_put_contents($file, $text)) { Logger::Log('POST AddPlatform failed, config.ini no access', LogLevel::ERROR); $this->app->response->setStatus(409); $this->app->stop(); } $platform = new Platform(); $platform->setStatus(201); $res[] = $platform; $this->app->response->setStatus(201); } if (!$arr && count($res) == 1) { $this->app->response->setBody(Platform::encodePlatform($res[0])); } else { $this->app->response->setBody(Platform::encodePlatform($res)); } }