Skip to content

Commit

Permalink
Change the routing method for building routes
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>

Update routes

Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Mar 2, 2021
1 parent cb93fa3 commit 9368b03
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 30 deletions.
45 changes: 45 additions & 0 deletions config/routes.php
Expand Up @@ -59,6 +59,51 @@
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);

$routes->connect('/stats', ['controller' => 'Stats', 'action' => 'stats']);

$routes->connect(
'/reports/view/{id}',
['controller' => 'Reports', 'action' => 'view'],
['_name' => 'reports:view']
)
->setPass(['id', 'reportId'])
->setPatterns([
'id' => '[0-9]+',
]);

$routes->connect(
'/github/sync_issue_status',
['controller' => 'Github', 'action' => 'sync_issue_status']
);

$routes->connect(
'/github/create_issue/{id}',
['controller' => 'Github', 'action' => 'create_issue'],
['_name' => 'github:create_issue']
)
->setPass(['id', 'reportId'])
->setPatterns([
'id' => '[0-9]+',
]);

$routes->connect(
'/github/unlink_issue/{id}',
['controller' => 'Github', 'action' => 'unlink_issue'],
['_name' => 'github:unlink_issue']
)
->setPass(['id', 'reportId'])
->setPatterns([
'id' => '[0-9]+',
]);

$routes->connect(
'/github/link_issue/{id}',
['controller' => 'Github', 'action' => 'link_issue'],
['_name' => 'github:link_issue']
)
->setPass(['id', 'reportId'])
->setPatterns([
'id' => '[0-9]+',
]);
/**
* Connect catchall routes for all controllers.
*
Expand Down
26 changes: 17 additions & 9 deletions src/Controller/GithubController.php
Expand Up @@ -115,8 +115,9 @@ public function create_issue(int $reportId): void
$report->status = $this->getReportStatusFromIssueState($issueDetails['state']);
$reportsTable->save($report);

$this->redirect(['controller' => 'reports', 'action' => 'view',
$reportId,
$this->redirect([
'_name' => 'reports:view',
'id' => $reportId,
]);
} else {
$flash_class = 'alert alert-error';
Expand Down Expand Up @@ -192,8 +193,9 @@ public function link_issue(int $reportId): void
);
}

$this->redirect(['controller' => 'reports', 'action' => 'view',
$reportId,
$this->redirect([
'_name' => 'reports:view',
'id' => $reportId,
]);
}

Expand Down Expand Up @@ -227,8 +229,10 @@ public function unlink_issue(int $reportId): void
$commentText = 'This Issue is no longer associated with [Report#'
. $reportId
. ']('
. Router::url('/reports/view/' . $reportId, true)
. ')'
. Router::url([
'_name' => 'reports:view',
'id' => $reportId,
], true) . ')'
. "\n\n*This comment is posted automatically by phpMyAdmin's "
. '[error-reporting-server](https://reports.phpmyadmin.net).*';

Expand All @@ -251,8 +255,9 @@ public function unlink_issue(int $reportId): void
);
}

$this->redirect(['controller' => 'reports', 'action' => 'view',
$reportId,
$this->redirect([
'_name' => 'reports:view',
'id' => $reportId,
]);
}

Expand Down Expand Up @@ -302,7 +307,10 @@ protected function getReportDescriptionText(int $reportId, array $report): strin
. "\n Link | [Report#"
. $reportId
. ']('
. Router::url('/reports/view/' . $reportId, true)
. Router::url([
'_name' => 'reports:view',
'id' => $reportId,
], true)
. ')'
. "\n\n*This comment is posted automatically by phpMyAdmin's "
. '[error-reporting-server](https://reports.phpmyadmin.net).*';
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/NotificationsController.php
Expand Up @@ -121,9 +121,8 @@ public function data_tables(): Response
$tmp_row[1] = '<a href="'
. Router::url(
[
'controller' => 'reports',
'action' => 'view',
$row['report_id'],
'_name' => 'reports:view',
'id' => $row['report_id'],
]
)
. '">'
Expand Down
6 changes: 2 additions & 4 deletions src/Model/Table/ReportsTable.php
Expand Up @@ -200,16 +200,14 @@ public function addToRelatedGroup(EntityInterface $report, int $related_to): voi
*/
public function getUrl(): string
{
return Router::url(['controller' => 'reports', 'action' => 'view',
$this->id,
], true);
return Router::url(['_name' => 'reports:view', 'id' => $this->id], true);
}

/**
* groups related incidents by distinct values of a field. It may also provide
* the number of groups, whether to only include incidents that are related
* to the current report and also to only limit the search to incidents
* submited after a certain date.
* submitted after a certain date.
*
* @param string $fieldName the name of the field to group by
* @param int $limit the max number of groups to return
Expand Down
22 changes: 13 additions & 9 deletions templates/Reports/view.php
Expand Up @@ -76,7 +76,10 @@
?>
<?=
'<form action="'
. Router::url('/github/unlink_issue/', true) . $report[0]['id']
. Router::url([
'_name' => 'github:unlink_issue',
'id' => $report[0]['id'],
])
. '" method="GET" class="form-horizontal" style="margin-bottom:5px;"'
. ' onclick="return window.confirm(\'Are you sure you want to unlink this report?\');" >';
?>
Expand All @@ -94,19 +97,20 @@
style="width:300px; margin-bottom:5px;">
<tr>
<td style="min-width:130px;">
<?=
$this->Html->link(
'Create new issue',
'/github/create_issue/' . $report[0]['id'],
['class' => 'btn btn-primary']
);
<?php
echo Router::url([
'_name' => 'github:create_issue',
'id' => $report[0]['id'],
]);
?>
</td>
<td style="min-width:130px;">
<?=
'<form action="'
. Router::url('/', true) . 'github/link_issue/'
. $report[0]['id'] . '" method="GET" '
. Router::url([
'_name' => 'github:link_issue',
'id' => $report[0]['id'],
]) . '" method="GET" '
. 'class="form-horizontal" style="margin-bottom:5px;">';
?>

Expand Down
12 changes: 7 additions & 5 deletions templates/email/html/report.php
@@ -1,4 +1,5 @@
<?php

/**
* Report Notification Email Template
*
Expand All @@ -14,11 +15,9 @@
*
* @see https://www.phpmyadmin.net/
*/
?>
<?php
use Cake\Routing\Router;

?>

<p>
A new error report has been added on the phpMyAdmin's Error Reporting System.
</p>
Expand Down Expand Up @@ -160,6 +159,9 @@

<p>
You can view the detailed report at
<a href="<?= Router::url('/reports/view/' . $report['id'], true) ?>">
<a href="<?= Router::url([
'_name' => 'reports:view',
'id' => $report['id'],
], true) ?>">
#<?= $report['id'] ?></a>.
</p>
</p>

0 comments on commit 9368b03

Please sign in to comment.