Skip to content

Commit

Permalink
Merge branch 'release/2.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Jun 5, 2020
2 parents f4ec296 + 6742db3 commit 73a5a70
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 2.5.1

* Fixes issues with redirect rules file not being present

# 2.5.0

* Add support for using relative paths

# 2.4.1

* Add Redirect Extensions promo page
Expand Down
3 changes: 2 additions & 1 deletion classes/PublishManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function publish(): int

private function publishToFilesystem(array $columns, array $redirects): void
{
$redirectsFile = storage_path('app/redirects.csv');
$redirectsFile = config('vdlp.redirect::rules_path');

if (file_exists($redirectsFile)) {
unlink($redirectsFile);
Expand All @@ -98,6 +98,7 @@ private function publishToFilesystem(array $columns, array $redirects): void
$writer->insertOne($row);
}
} catch (Throwable $e) {
touch($redirectsFile);
$this->log->error($e);
}
}
Expand Down
5 changes: 4 additions & 1 deletion classes/RedirectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function matchCached(string $requestPath, string $scheme)

try {
$matchedRule = $this->match($requestPath, $scheme);
} catch (Exceptions\NoMatchForRequest | Exceptions\InvalidScheme $e) {
} catch (Exceptions\NoMatchForRequest | Exceptions\InvalidScheme | Exceptions\UnableToLoadRules $e) {
$matchedRule = null;
}

Expand Down Expand Up @@ -564,7 +564,10 @@ private function loadRulesFromFilesystem(): array
$results = $reader->fetchAssoc(0);
} else {
// Supports league/csv:9.0+
/** @noinspection PhpUndefinedMethodInspection */
$reader->setHeaderOffset(0);

/** @noinspection PhpUndefinedMethodInspection */
$results = $reader->getRecords();
}
} catch (Throwable $e) {
Expand Down
2 changes: 2 additions & 0 deletions classes/contracts/RedirectManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Vdlp\Redirect\Classes\Exceptions\InvalidScheme;
use Vdlp\Redirect\Classes\Exceptions\NoMatchForRequest;
use Vdlp\Redirect\Classes\Exceptions\UnableToLoadRules;
use Vdlp\Redirect\Classes\RedirectManagerSettings;
use Vdlp\Redirect\Classes\RedirectRule;

Expand All @@ -27,6 +28,7 @@ public static function createWithRule(RedirectRule $rule): RedirectManagerInterf
* @return RedirectRule
* @throws InvalidScheme
* @throws NoMatchForRequest
* @throws UnableToLoadRules
*/
public function match(string $requestPath, string $scheme): RedirectRule;

Expand Down
14 changes: 8 additions & 6 deletions controllers/Redirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace Vdlp\Redirect\Controllers;

use ApplicationException;
use Backend;
use Backend\Behaviors;
use Backend\Classes\Controller;
use Backend\Classes\FormField;
use Backend\Facades\Backend;
use Backend\Facades\BackendMenu;
use Backend\Widgets\Form;
use BackendMenu;
use Carbon\Carbon;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Translation\Translator;
Expand All @@ -19,12 +18,15 @@
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use October\Rain\Database\Model;
use October\Rain\Exception\ApplicationException;
use October\Rain\Exception\SystemException;
use October\Rain\Flash\FlashBag;
use System\Models\RequestLog;
use SystemException;
use Throwable;
use Vdlp\Redirect\Classes\Contracts\CacheManagerInterface;
use Vdlp\Redirect\Classes\Exceptions\InvalidScheme;
use Vdlp\Redirect\Classes\Exceptions\NoMatchForRequest;
use Vdlp\Redirect\Classes\Exceptions\UnableToLoadRules;
use Vdlp\Redirect\Classes\RedirectManager;
use Vdlp\Redirect\Classes\RedirectRule;
use Vdlp\Redirect\Classes\StatisticsHelper;
Expand Down Expand Up @@ -426,7 +428,7 @@ public function onTest(): array
$testDate = Carbon::createFromFormat('Y-m-d', $this->request->get('test_date', date('Y-m-d')));
$manager->setMatchDate($testDate);
$match = $manager->match($inputPath, $this->request->get('test_scheme', $this->request->getScheme()));
} catch (NoMatchForRequest $e) {
} catch (NoMatchForRequest | InvalidScheme | UnableToLoadRules $e) {
$match = false;
} catch (Throwable $e) {
throw new ApplicationException($e->getMessage());
Expand All @@ -435,7 +437,7 @@ public function onTest(): array
return [
'#testResult' => $this->makePartial('redirect_test_result', [
'match' => $match,
'url' => $match ? $manager->getLocation($match) : '',
'url' => $match && isset($manager) ? $manager->getLocation($match) : '',
]),
];
}
Expand Down
2 changes: 2 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@
- "Add Redirect Extensions promo page -- See: https://github.com/vdlp/oc-redirect-plugin/releases/tag/2.4.1"
2.5.0:
- "Add support for using relative paths -- See: https://github.com/vdlp/oc-redirect-plugin/releases/tag/2.5.0"
2.5.1:
- "Fixes issues with redirect rules file not being present -- See: https://github.com/vdlp/oc-redirect-plugin/releases/tag/2.5.1"

0 comments on commit 73a5a70

Please sign in to comment.