statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.09k stars 534 forks source link

Addon update called many times #11082

Open edalzell opened 2 weeks ago

edalzell commented 2 weeks ago

Bug description

Our addon's updater gets called many times: CleanShot 2024-11-06 at 15 56 37@2x

How to reproduce

Run composer dump-autoload when your add-on's updater looks like:

<?php

namespace TransformStudios\Simple\UpdateScripts;

use Illuminate\Support\Facades\App;
use Statamic\UpdateScripts\UpdateScript;
use TransformStudios\Simple\SimpleFacade as Simple;

class Updater extends UpdateScript
{
    public function shouldUpdate($newVersion, $oldVersion)
    {
        return App::isLocal();
    }

    public function update()
    {
        Simple::updateConfigs();
        Simple::publishFiles();
        Simple::setDigitalGuidelineSites();
    }
}

It's using the auto-loading that was recently added.

Logs

No response

Environment

Environment
Application Name: Sacramento Airport
Laravel Version: 11.30.0
PHP Version: 8.3.13
Composer Version: 2.7.7
Environment: local
Debug Mode: ENABLED
URL: sacair.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: null
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Livewire
Livewire: v3.5.12

Statamic
Addons: 13
Sites: 6 (Sacramento Airport, Sacramento County Department of Airports, Sacramento International Airport, and 3 more)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.37.0 PRO

Statamic Addons
aryehraber/statamic-captcha: 1.13.0
edalzell/forma: 3.0.1
jacksleight/statamic-bard-mutator: 2.3.1
jacksleight/statamic-distill: 0.8.0
jonassiewertsen/statamic-livewire: 3.8.1
statamic-rad-pack/runway: 7.12.0
statamic/seo-pro: 6.3.0
transformstudios/events: 5.4.3
transformstudios/front: 3.0.1
transformstudios/github: dev-main
transformstudios/review: 5.0
transformstudios/simple: dev-fix/user-migrations
transformstudios/skidata: dev-main

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

duncanmcclean commented 1 week ago

I'm unable to reproduce this with a fresh site & addon. 🤔

CleanShot 2024-11-11 at 15 11 51

What does your addon's ServiceProvider look like?

edalzell commented 1 week ago

Oh I bet it has something to with the fact I load a bunch of service providers in the composer.json:

CleanShot 2024-11-13 at 15 40 15@2x

edalzell commented 1 week ago

Yup, 9 service providers and it's called 9 times

duncanmcclean commented 1 week ago

Do all of those service providers extend Statamic's AddonServiceProvider?

edalzell commented 1 week ago

Do all of those service providers extend Statamic's AddonServiceProvider?

Yes they do, because they have tags etc and I want them loaded.

duncanmcclean commented 1 week ago

Okay! We can probably provide a way to opt-out of auto registration then.

edalzell commented 1 week ago

Okay! We can probably provide a way to opt-out of auto registration then.

How will that help? I only have ONE update script at the correct relative location, why is that one getting called for the other service providers?

duncanmcclean commented 1 week ago

For the record: we've chatted this out on Slack. Instead of autoloading based on the addon's path, we can use the service provider's path.