/** * Update data of an item via POST-request. */ public function push_data_action() { if (Request::isPost()) { $public_key_hash = $_SERVER['HTTP_' . str_replace("-", "_", strtoupper($GLOBALS['LERNMARKTPLATZ_HEADER_PUBLIC_KEY_HASH']))]; $signature = base64_decode($_SERVER['HTTP_' . str_replace("-", "_", strtoupper($GLOBALS['LERNMARKTPLATZ_HEADER_SIGNATURE']))]); $host = LernmarktplatzHost::findOneBySQL("MD5(public_key) = ?", array($public_key_hash)); if ($host && !$host->isMe()) { $body = file_get_contents('php://input'); if ($host->verifySignature($body, $signature)) { $data = studip_utf8decode(json_decode($body, true)); $material = LernmarktplatzMaterial::findOneBySQL("host_id = ? AND foreign_material_id = ?", array($host->getId(), $data['data']['foreign_material_id'])); if (!$material) { $material = new LernmarktplatzMaterial(); } if ($data['delete_material']) { $material->delete(); echo "deleted "; } else { $material->setData($data['data']); $material['host_id'] = $host->getId(); //update user $user = LernmarktplatzUser::findOneBySQL("host_id = ? AND foreign_user_id = ?", array($host->getId(), $data['user']['user_id'])); if (!$user) { $user = new LernmarktplatzUser(); $user['host_id'] = $host->getId(); $user['foreign_user_id'] = $data['user']['user_id']; } $user['name'] = $data['user']['name']; $user['avatar'] = $data['user']['avatar']; $user['description'] = $data['user']['description'] ?: null; $user->store(); $material['user_id'] = $user->getId(); $material->store(); $material->setTopics($data['topics']); echo "stored "; } } else { throw new Exception("Wrong signature, sorry."); } } $this->render_text(""); } else { throw new Exception("USE POST TO PUSH."); } }