private static function saveMutation($operation, $fullRelationSignature, $stableAtom, $stableConcept, $modifiedAtom, $modifiedConcept, $source) { if (array_key_exists($fullRelationSignature, Config::get('mutationConcepts', 'MutationExtension'))) { Notifications::addLog("Save mutation on '{$fullRelationSignature}' (editUpdate)", 'Mutation'); $mutConcept = Config::get('mutationConcepts', 'MutationExtension')[$fullRelationSignature]; $database = Database::singleton(); $database->setTrackAffectedConjuncts(false); // Don't track affected conjuncts for Mutation concept and relations; // New Mutation $mut = $database->addAtomToConcept(Concept::createNewAtom($mutConcept), $mutConcept); // Add mut info $database->editUpdate('mutRelation', false, $mut, 'Mutation', $fullRelationSignature, 'Relation'); $database->editUpdate('mutDateTime', false, $mut, 'Mutation', date(DATE_ISO8601), 'DateTime'); if ($source == 'User') { $user = Session::getSessionUserId(); } else { $user = $source; } $database->editUpdate('mutBy', false, $mut, 'Mutation', $user, 'User'); $database->editUpdate('mutOp', false, $mut, 'Mutation', $operation, 'Operation'); // $database->editUpdate('mutReason', false, $mut, 'Mutation', 'zomaar', 'MutationReason'); // TODO: get reason from somewhere $database->editUpdate('mutValue', false, $mut, 'Mutation', $modifiedAtom, 'MutationValue'); $database->editUpdate('mutStable', false, $mut, $mutConcept, $stableAtom, $stableConcept); $database->editUpdate('mutPublish', false, $mut, 'Mutation', $mut, 'Mutation'); $database->setTrackAffectedConjuncts(true); // Enable tracking of affected conjuncts again!! } }
/** * @url POST resource/{concept}/{srcAtomId}/{interfaceId} * @param string $concept * @param string $srcAtomId * @param string $interfaceId * @param array $roleIds * @param string $requestType * * RequestType: reuqest for 'feedback' (try) or request to 'promise' (commit if possible). */ public function postAtom($concept, $srcAtomId, $interfaceId, $roleIds = null, $requestType = 'feedback', $request_data = null) { try { $session = Session::singleton(); $session->activateRoles($roleIds); $session->setInterface($interfaceId); if (!$session->interface->crudC) { throw new Exception("POST is not allowed for interface " . $session->interface->label, 405); } $concept = $session->interface->tgtConcept; $atomId = $request_data['id'] ? $request_data['id'] : Concept::createNewAtom($concept); if ($session->database->atomExists($atomId, $concept)) { throw new Exception("Resource already exists. POST method is not allowed", 405); } $newAtomId = $session->database->addAtomToConcept($atomId, $concept); $session->atom = new Atom($newAtomId, $concept); return $session->atom->post($session->interface, $request_data, $requestType); } catch (Exception $e) { throw new RestException($e->getCode(), $e->getMessage()); } }
private function ParseLines($data) { $relation = $concept = $atom = array(); foreach ($data as $linenr => $values) { $totalcolumns = count($values); if ($linenr == 0) { // Relations: for ($col = 0; $col < $totalcolumns; $col++) { $relation[$col] = $values[$col]; } } elseif ($linenr == 1) { // Concepts: for ($col = 0; $col < $totalcolumns; $col++) { $concept[$col] = $values[$col]; } } else { // Atoms: for ($col = 0; $col < $totalcolumns; $col++) { $atom[$col] = $values[$col]; } // Don't process lines that start with an empty first cell if ($atom[0] == '' or empty($atom[0])) { continue; } // Check if this is an atom-create line, syntax = &atomname if (strpos('&', $atom[0]) === 0) { $atom[0] = Concept::createNewAtom($concept[0]); // Create a unique atom name } // Insert $atom[0] into the DB if it does not yet exist $this->addAtomToConcept($atom[0], $concept[0]); for ($col = 1; $col < $totalcolumns; $col++) { // Now we transform the data info function calls: if ($atom[$col] == '') { continue; } // Empty cells are allowed but shouldn't do anything if ($concept[$col] == '' or empty($concept[$col])) { continue; } // if no concept is specified, the contents of the cell should be ignored. if ($relation[$col] == '' or empty($relation[$col])) { continue; } // if no relation is specified, the contents of the cell should be ignored. if (strpos('&', $atom[$col]) === 0) { // Check if this is an atom-create line, syntax = &atomname $atom[$col] = $atom[0]; // '&' copies the atom-value; useful for property-relations. } $this->insertRel($relation[$col], $atom[0], $atom[$col], $concept[0], $concept[$col]); } $atom = array(); } } }
private function callback($code, $idp) { try { $identityProviders = Config::get('identityProviders', 'OAuthLogin'); if (empty($code)) { throw new Exception("Oops. Someting went wrong during login. Please try again", 401); } $session = Session::singleton(); $db = Database::singleton(); if (!isset($identityProviders[$idp])) { throw new Exception("Unknown identity provider", 500); } $client_id = $identityProviders[$idp]['clientId']; $client_secret = $identityProviders[$idp]['clientSecret']; $redirect_uri = $identityProviders[$idp]['redirectUrl']; $token_url = $identityProviders[$idp]['tokenUrl']; $api_url = $identityProviders[$idp]['apiUrl']; $emailField = $identityProviders[$idp]['emailField']; // instantiate authController $authController = new OAuthLoginController($client_id, $client_secret, $redirect_uri, $token_url); // request token if ($authController->requestToken($code)) { // request data if ($authController->requestData($api_url)) { // Verify email/role here $email = $authController->getData()->{$emailField}; // Get user with $email // Set sessionUser $interface = new InterfaceObject('EmailUser'); $atom = new Atom($email, 'Email'); $users = array_keys((array) $atom->getContent($interface, true)); // create new user if (empty($users)) { $newUser = Concept::createNewAtom('User'); $db->addAtomToConcept($newUser, 'User'); $db->editUpdate('userEmail', false, $newUser, 'User', $email, 'Email'); // add to Organization $domain = explode('@', $email)[1]; $interface = new InterfaceObject('DomainOrgs'); $atom = new Atom($domain, 'Domain'); $orgs = array_keys((array) $atom->getContent($interface, true)); foreach ($orgs as $org) { $db->editUpdate('userOrganization', false, $newUser, 'User', $org, 'Organization'); } $users[] = $newUser; } if (count($users) > 1) { throw new Exception("Multiple users registered with email {$email}", 401); } foreach ($users as $userId) { // Set sessionUser $db->editUpdate('sessionUser', false, session_id(), 'SESSION', $userId, 'User'); // Timestamps $db->editUpdate('userLastLoginTimeStamp', false, $userId, 'User', date(DATE_ISO8601), 'DateTime'); $db->editUpdate('userLoginTimeStamp', false, $userId, 'User', date(DATE_ISO8601), 'DateTime'); } $db->closeTransaction('Login successfull', false, true, false); } } header('Location: ' . Config::get('serverURL')); exit; } catch (Exception $e) { throw new RestException($e->getCode(), $e->getMessage()); } }
function InsAtom($concept) { if (func_num_args() != 1) { throw new Exception("Wrong number of arguments supplied for function InsAtom(): " . func_num_args() . " arguments", 500); } Notifications::addLog("InsAtom({$concept})", 'ExecEngine'); try { $database = Database::singleton(); $atom = Concept::createNewAtom($concept); $database->addAtomToConcept($atom, $concept); // insert new atom in database return "Atom '" . $atom . "' added to concept '" . $concept . "'"; } catch (Exception $e) { Notifications::addError('InsAtom: ' . $e->getMessage()); } }