Skip to content

Data repository problem when invalidating URL #40

Description

@SteJW

I'm using:
Statamic 6
thoughtco/statamic-cache-tracker 2.4.0
Latest eloquent driver

When I'm viewing the URL's in the CP, I'm having an error. Not really sure if it's because of Eloquent or not.

{
    "message": "Undefined array key 1",
    "exception": "ErrorException",
    "file": "/var/www/vdu-statamic/vendor/statamic/eloquent-driver/src/Taxonomies/TermRepository.php",
    "line": 25,
    "trace": [
        {
            "file": "/var/www/vdu-statamic/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php",
            "line": 364,
            "function": "find",
            "class": "Statamic\\Data\\DataRepository",
            "type": "->"
        },
        {
            "file": "/var/www/vdu-statamic/vendor/thoughtco/statamic-cache-tracker/src/Http/Controllers/GetUrlsController.php",
            "line": 19,
            "function": "__callStatic",
            "class": "Illuminate\\Support\\Facades\\Facade",
            "type": "::"
        },
        {
            "file": "/var/www/vdu-statamic/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "__invoke",
            "class": "Thoughtco\\StatamicCacheTracker\\Http\\Controllers\\GetUrlsController",
            "type": "->"
        }
    ]
}

When I change GetUrlsController to the following, it returns everything in the console, but it doesn't show in the modal.

<?php

namespace Thoughtco\StatamicCacheTracker\Http\Controllers;

use Statamic\Contracts\Entries\Entry;
use Statamic\Contracts\Taxonomies\Term;
use Statamic\Facades\Entry as EntryFacade;
use Statamic\Http\Controllers\Controller;
use Thoughtco\StatamicCacheTracker\Facades\Tracker;

class GetUrlsController extends Controller
{
    public function __invoke(): array
    {
        if (! $url = request()->input('url')) {
            return [];
        }

        $path = parse_url($url, PHP_URL_PATH);
        if (! $item = EntryFacade::findByUri($path)) {
            return [];
        }

        if ($item instanceof Entry) {
            $item = $item->collectionHandle().':'.$item->id();
        }

        if ($item instanceof Term) {
            $item = 'term:'.$item->id();
        }

        return collect(Tracker::all())
            ->filter(fn ($tracked) => in_array($item, $tracked['tags']))
            ->all();
    }
}
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions