/** * @param Site $site * @param ActionInterface $action * @param array $options * * @return Promise */ public function sendAsync(Site $site, ActionInterface $action, array $options = []) { $options += ['oxygen_site' => $site, 'oxygen_action' => $action, RequestOptions::ALLOW_REDIRECTS => ['max' => 1, 'strict' => true, 'referrer' => true], RequestOptions::VERIFY => false]; $request = new Request('POST', $site->getUrl(), ['cookie' => 'XDEBUG_SESSION=PHPSTORM']); $fn = $this->handler; return $fn($request, $options); }
/** * @Method("GET|POST") * @Route("extension.update", name="api-project.update") * @ParamConverter("site", class="Model:Site", options={"request_path":"site", "query_path":"site", "repository_method":"findOneByUid"}) * @Api("Undine\Form\Type\Api\ExtensionUpdateType") */ public function downloadUpdateFromUrlAction(Site $site, ExtensionUpdateCommand $command) { $updates = $site->getSiteState()->getSiteUpdates(); if (!isset($updates[$command->getExtension()])) { throw $this->createNotFoundException('The extension could not be found.'); } $extension = $command->getExtension(); $url = $updates[$command->getExtension()]->getRecommendedDownloadLink(); $reaction = $this->oxygenClient->sendAsync($site, new ExtensionDownloadUpdateFromUrlAction($extension, $url))->then(function (ExtensionDownloadUpdateFromUrlReaction $reaction) use($site, $extension) { return $this->oxygenClient->sendAsync($site, new ExtensionUpdateAction($extension)); })->then(function (ExtensionUpdateReaction $reaction) use($site) { return $this->oxygenClient->sendAsync($site, new DatabaseListMigrationsAction()); })->then(function (DatabaseListMigrationsReaction $reaction) use($site) { $migrationGenerator = function () use($site, $reaction) { foreach ($reaction->getMigrations() as $migration) { (yield $this->oxygenClient->sendAsync($site, new DatabaseRunMigrationAction($migration['module'], $migration['number'], $migration['dependencyMap']))); } }; return \GuzzleHttp\Promise\each_limit_all($migrationGenerator(), 1); })->wait(); return new ExtensionUpdateResult(); }
/** * @param Site $site * @param string $userId ID of the user that initiates the session. It is used to track individual sessions so they can be destroyed * on demand. This value is signed, so it cannot be intercepted. * @param string|null $userName User to log in as. Pass null to use the user with ID 1, which should always exist and have full privileges * (hardcoded in Drupal). This value is signed, so it cannot be intercepted. * * @return UriInterface */ public function generateUrl(Site $site, $userId, $userName = null) { $requestId = bin2hex(random_bytes(16)); $requestExpiresAt = time() + 86400; $query = ['oxygenRequestId' => $requestId, 'requestExpiresAt' => $requestExpiresAt, 'actionName' => 'site.login', 'signature' => \Undine\Functions\openssl_sign_data($site->getPrivateKey(), sprintf('%s|%d|%s|%s', $requestId, $requestExpiresAt, $userId, (string) $userName)), 'userName' => $userName, 'userId' => $userId]; $url = $site->getUrl(); if ($site->hasHttpCredentials()) { $url = $url->withUserInfo($site->getHttpCredentials()->getUsername(), $site->getHttpCredentials()->getPassword()); } return $url->withQuery(\GuzzleHttp\Psr7\build_query($query)); }
/** * Returns a list of parameters that should be passed to the Oxygen module's AttachStateListener. * For example, this method attaches 'extensionsChecksum' property, and if it does not match with the 'system' table checksum * on the Drupal site that the Oxygen module is on, the module returns full table as a result, and the new checksum. * * @param Site $site * * @return array */ public function getParameters(Site $site) { return ['extensionsChecksum' => $site->getSiteState()->getExtensionsChecksum()]; }
public function includeState(Site $site) { return $this->item($site->getSiteState(), $this->transformers->get(SiteState::class)); }