public static function Init($data) { $component = new Component(); $links = array(); $link = new Link(); $link->setName('fileDb'); $link->setAddress('http://localhost/' . $data['path'] . '/fileDb'); $link->setPrefix('file'); $links[] = $link; $link = new Link(); $link->setName('file'); $link->setAddress('http://localhost/' . $data['path'] . '/file'); $link->setPrefix('file'); $links[] = $link; $component->setLinks($links); chdir(dirname(__FILE__)); CConfig::saveConfigGlobal('', Component::encodeComponent($component)); }
public static function loadStaticConfig($pref, $pre, $path = '', $file = null) { CConfig::$onload = true; if ($path != '') { $path .= '/'; } $path = str_replace("\\", '/', $path); $ff = $path . $pre . CConfig::$CONF_FILE; if ($file != null) { $ff = $path . $file; } if (file_exists($ff)) { // file was found, create a Component object from file content $com = Component::decodeComponent(file_get_contents($ff)); $com->setPrefix($pref); // check if the links // know their prefixes $conf = $com; $links = $conf->getLinks(); // always been an array if (!is_array($links)) { $links = array($links); } $changed = false; foreach ($links as &$link) { // if a link has no prefix, we have to ask the link target // for the prefix list if ($link->getPrefix() === null) { $result = Request::get($link->getAddress() . '/control', array(), ''); if ($result['status'] == 200) { // the link target has send its component definition, // so that we can remember this $changed = true; $obj = Component::decodeComponent($result['content']); $link->setPrefix($obj->getPrefix()); $link->setClassFile($obj->getClassFile()); $link->setClassName($obj->getClassName()); $link->setLocalPath($obj->getLocalPath()); } } } // if any new prefix was found, we have to store the link definitions if ($changed) { $conf->setLinks($links); CConfig::saveConfigGlobal($pre, Component::encodeComponent($conf), substr($path, 0, -1), $file); $com = $conf; } CConfig::$onload = false; return $com; } else { // can't find the file, create an empty object $com = new Component(); $com->setPrefix($pref); CConfig::$onload = false; return $com; } CConfig::$onload = false; }
/** * Initializes all components, with the data, which can be found in database. */ public function sendComponentDefinitions() { $this->_app->response->setStatus(200); // starts a query ob_start(); eval("?>" . file_get_contents(dirname(__FILE__) . '/Sql/GetComponentDefinitions.sql')); $sql = ob_get_contents(); ob_end_clean(); $result = DBRequest::request($sql, false, parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE)); // checks the correctness of the query if ((!isset($result['errno']) || !$result['errno']) && $result['content']) { $data = DBJson::getRows($result['content']); $Components = DBJson::getObjectsByAttributes($data, Component::getDBPrimaryKey(), Component::getDBConvert()); $Links = DBJson::getObjectsByAttributes($data, Link::getDBPrimaryKey(), Link::getDBConvert()); $objects = DBJson::concatResultObjectLists($data, $Components, Component::getDBPrimaryKey(), Component::getDBConvert()['CO_links'], $Links, Link::getDBPrimaryKey()); $request = new Request_MultiRequest(); $data = parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE); $tempObjects = array(); foreach ($objects as $object) { $object = Component::decodeComponent(json_encode($object)); // prüfen, welche Komponente auf diesem Server ist if (strpos($object->getAddress() . '/', $data['PL']['urlExtern'] . '/') === false) { continue; } $object->setAddress($data['PL']['url'] . substr($object->getAddress(), strlen($data['PL']['urlExtern']))); $links = $object->getLinks(); foreach ($links as &$link) { if (strpos($link->getAddress() . '/', $data['PL']['urlExtern'] . '/') === false) { continue; } $link->setAddress($data['PL']['url'] . substr($link->getAddress(), strlen($data['PL']['urlExtern']))); } $object->setLinks($links); $result = Request_CreateRequest::createPost($object->getAddress() . '/control', array(), Component::encodeComponent($object)); $tempObjects[] = $object; $request->addRequest($result); } $results = $request->run(); $objects = $tempObjects; $i = 0; $res = array(); foreach ($objects as $object) { $object = Component::decodeComponent(Component::encodeComponent($object)); $result = $results[$i++]; $newObject = new Component(); $newObject->setId($object->getId()); $newObject->setName($object->getName()); $newObject->setAddress($object->getAddress()); $newObject->setDef($object->getDef()); $newObject->setStatus($result['status']); $res[] = $newObject; if ($result['status'] != 201) { $add = ''; $this->_app->response->setStatus(409); if (isset($result['content'])) { $add = $result['content']; } Logger::Log($result['status'] . '--' . $object->getName() . '--' . $object->getAddress() . "\n" . $add . "\n", LogLevel::ERROR); } } $this->_app->response->setBody(json_encode($res)); } else { Logger::Log('GET SendComponentDefinitions failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); } }
public static function install($data, &$fail, &$errno, &$error) { $fail = false; $url = $data['PL']['init']; $components = array(); // inits all components $result = Request::get($data['PL']['url'] . '/' . $url . '/definition/send', array(), ''); //echo $result['content']; if (isset($result['content']) && isset($result['status'])) { // component routers $router = array(); $results = Component::decodeComponent($result['content']); $results = Installation::orderBy(json_decode(Component::encodeComponent($results), true), 'name', SORT_ASC); $results = Component::decodeComponent(json_encode($results)); if (!is_array($results)) { $results = array($results); } if (count($results) == 0) { $fail = true; $error = Language::Get('components', 'noComponents'); } foreach ($results as $res) { $components[$res->getName()] = array(); $components[$res->getName()]['init'] = $res; } // get component definitions from database $result4 = Request::get($data['PL']['url'] . '/' . $url . '/definition', array(), ''); if (isset($result4['content']) && isset($result4['status']) && $result4['status'] === 200) { $definitions = Component::decodeComponent($result4['content']); if (!is_array($definitions)) { $definitions = array($definitions); } if (count($definitions) == 0) { $fail = true; $error = Language::Get('components', 'noDefinitions'); } $result2 = new Request_MultiRequest(); $result3 = new Request_MultiRequest(); $tempDef = array(); foreach ($definitions as $definition) { if (strpos($definition->getAddress() . '/', $data['PL']['urlExtern'] . '/') === false) { continue; } $components[$definition->getName()]['definition'] = $definition; $tempDef[] = $definition; $request = Request_CreateRequest::createGet($definition->getAddress() . '/info/commands', array(), ''); $result2->addRequest($request); $request = Request_CreateRequest::createGet($definition->getAddress() . '/info/links', array(), ''); $result3->addRequest($request); } $definitions = $tempDef; $result2 = $result2->run(); $result3 = $result3->run(); foreach ($results as $res) { if ($res === null) { $fail = true; continue; } $countLinks = 0; $resultCounter = -1; foreach ($definitions as $definition) { //if (strpos($definition->getAddress().'/', $data['PL']['urlExtern'].'/')===false) continue; $resultCounter++; if ($definition->getId() === $res->getId()) { $links = $definition->getLinks(); $links = Installation::orderBy(json_decode(Link::encodeLink($links), true), 'name', SORT_ASC); $links = Link::decodeLink(json_encode($links)); if (!is_array($links)) { $links = array($links); } $components[$definition->getName()]['links'] = $links; if (isset($result2[$resultCounter]['content']) && isset($result2[$resultCounter]['status']) && $result2[$resultCounter]['status'] === 200) { $commands = json_decode($result2[$resultCounter]['content'], true); if ($commands !== null) { $components[$definition->getName()]['commands'] = $commands; } } if (isset($result3[$resultCounter]['content']) && isset($result3[$resultCounter]['status']) && $result3[$resultCounter]['status'] === 200) { $calls = json_decode($result3[$resultCounter]['content'], true); $components[$definition->getName()]['call'] = $calls; } break; } } if ($res->getStatus() !== 201) { $fail = true; } } } else { $fail = true; $error = Language::Get('components', 'noDefinitions'); } } else { $fail = true; $error = Language::Get('components', 'operationFailed'); } if (isset($result['status']) && $result['status'] !== 200) { $fail = true; $error = Language::Get('components', 'operationFailed'); $errno = $result['status']; } return $components; }