Skip to content
Quiet Social

Adopting the package on an existing database

This documentation is translated from French. Should the two versions differ, the French version prevails.

Read this before adding PublishesToSocial to a model that already has rows: without the social:baseline command, the first save of each existing model publishes its post, and an old article whose typo is fixed would be posted on your networks the same day.

What the command does

social:baseline records the post each existing model describes today, without sending anything: no call reaches the API. From then on, a model is published only once its post changes, or when publishToSocial() asks for it.

php artisan social:baseline "App\Models\Article" "App\Models\Event" --chunk=500

It takes one or several classes, or morph aliases. It reads the models without global scopes, --chunk at a time (200 by default), and for each one:

  • a model whose condition holds (when, skip, shouldPublishSocially()) and that has no post of the synchronisation yet gets a baseline link: the fingerprint of its post, never sent;
  • a model whose condition is false is left out: it is published the day its condition becomes true, as a new post should be;
  • a model whose publication date is still ahead is left out, counted as "scheduled in the future": it must leave at its date, and its next save (or publishToSocial()) sends it;
  • a model in the bin (soft deleted) is left out;
  • a model whose synchronisation runs at that moment is left out, counted as "being synchronised": the command takes the same lock as the synchronisation, waiting lock_wait seconds for it;
  • a model that already has a post of the synchronisation is left out: the command can run twice;
  • a model that describes an invalid post is left out, with a warning.

It prints one line per class, and fails for a class that is not an Eloquent model using PublishesToSocial:

App\Models\Article: 120 recorded, 3 scheduled in the future, 0 being synchronised, 7 left out.
  1. Turn the synchronisation off for the deployment: QUIET_SOCIAL_SYNC_ENABLED=false.
  2. Deploy the code that adds PublishesToSocial and its description, then run php artisan migrate.
  3. Record the existing models with php artisan social:baseline, class by class or all at once.
  4. Turn the synchronisation back on (remove the variable or set it to true), refresh a cached configuration with php artisan config:cache, and restart the workers with php artisan queue:restart.

The command can also run with the synchronisation on: a model saved in between is then published, as it should be, and the command leaves it out.

What protects you without the command

The ignore_older_than limit (one day by default) prevents a model whose publication date is old from being sent automatically. It is a second safety net, not a substitute: a model without a publication date is never too old, and a model dated less than a day ago still goes out.

After the command, publishToSocial() still sends a post recorded as baseline: this is the way to deliberately republish an old model.