Skip to content

Commit

Permalink
Minor changes in webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsykun committed Jan 3, 2020
1 parent 56b1ebf commit 55b22a9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
18 changes: 11 additions & 7 deletions src/Packagist/WebBundle/Repository/PackageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,17 @@ function ($item) {
private function checkExtension($extensionName)
{
$conn = $this->getEntityManager()->getConnection();
$count = $conn
->executeQuery(
'SELECT COUNT(1) as v FROM pg_extension WHERE extname = :name',
[
'name' => $extensionName
]
)->fetch();
try {
$count = $conn
->executeQuery(
'SELECT COUNT(1) as v FROM pg_extension WHERE extname = :name',
[
'name' => $extensionName
]
)->fetch();
} catch (\Exception $exception) {
return false;
}

return isset($count['v']) && $count['v'] === 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Packagist/WebBundle/Repository/VersionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function getPreviousRelease(string $package, string $version)
$result = null;
$versions = $versions ? array_column($versions, 'version') : null;
foreach ($versions as $candidate) {
if (version_compare($version, $candidate) < 0) {
if (version_compare($version, $candidate) <= 0) {
continue;
}
if ($result === null || version_compare($result, $candidate) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Packagist/WebBundle/Resources/config/twig_sandbox.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
security_policy_tags: ['app', 'for', 'if', 'spaceless', 'set', 'apply', 'verbatim']
security_policy_tags: ['app', 'for', 'if', 'spaceless', 'set', 'do', 'apply', 'verbatim']
security_policy_functions: ['attribute', 'cycle', 'date', 'max', 'min', 'random', 'range', 'constant']
security_policy_methods: []
security_policy_forbidden_classes:
Expand Down
7 changes: 4 additions & 3 deletions src/Packagist/WebBundle/Webhook/HookTestAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ private function processChildWebhook(Webhook $webhook, array $context, HttpClien
if (isset($runtimeContext[WebhookContext::CHILD_WEBHOOK])) {
/** @var Webhook $childHook */
foreach ($runtimeContext[WebhookContext::CHILD_WEBHOOK] as list($childHook, $childContext)) {
if (null !== $childHook->getOwner() && $childHook->getOwner() !== $webhook->getOwner()) {
if (null !== $childHook->getOwner() && $childHook->getVisibility() === Webhook::USER_VISIBLE && $childHook->getOwner() !== $webhook->getOwner()) {
$response[] = new HookErrorResponse('You can not call private webhooks of another user owner, please check nesting webhook visibility');
continue;
}
$child = $this->processChildWebhook($webhook, $childContext, $client, $nestingLevel+1);
$child = $this->processChildWebhook($childHook, $childContext, $client, $nestingLevel+1);
$response = array_merge($response, $child);
}
}
Expand Down Expand Up @@ -159,7 +160,7 @@ private function selectVersion(array &$data): void
$collection = $collection->filter(function (Version $version) use ($versions) {
return in_array($version->getVersion(), $versions);
});
$data['versions'] = $collection->toArray();
$data['versions'] = array_values($collection->toArray());
} elseif ($ver = $collection->first()) {
$data['versions'] = [$ver];
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Packagist/WebBundle/Webhook/SenderWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function processChildWebhook(Webhook $parent, int $nestingLevel, array
{
/** @var Webhook $hook */
foreach ($child as list($hook, $context)) {
if (null !== $hook->getOwner() && $hook->getOwner() !== $parent->getOwner()) {
if (null !== $hook->getOwner() && $hook->getVisibility() === Webhook::USER_VISIBLE && $hook->getOwner() !== $parent->getOwner()) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Packagist/WebBundle/Webhook/Twig/WebhookExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function hook_function_get_changelog($package, $fromVersion = null, $toVe
}

if (!is_string($fromVersion)) {
$toVersion = $this->registry->getRepository(Version::class)
$fromVersion = $this->registry->getRepository(Version::class)
->getPreviousRelease($package->getName(), $toVersion);
}
if ($toVersion && $fromVersion) {
Expand All @@ -77,7 +77,7 @@ public function hook_function_get_changelog($package, $fromVersion = null, $toVe
return [];
}

public function hook_function_preg_match_all($regex, $content, $matchOffset = 1)
public function hook_function_preg_match_all($regex, $content, $matchOffset = null)
{
try {
@preg_match_all($regex, $content, $matches);
Expand Down

0 comments on commit 55b22a9

Please sign in to comment.