Skip to content
Quiet Social

Publishing, cancelling and previewing by hand

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

The PublishesToSocial trait gives the model three methods: publishToSocial() forces the synchronisation, cancelSocialPublication() cancels the post without waiting, and toSocialPost() shows the post without sending anything.

Forcing the publication

$article->publishToSocial();

Queues the synchronisation of the model now, forced:

  • its condition (when, skip, shouldPublishSocially()), its age (ignore_older_than) and a disabled sync are ignored;
  • an unchanged post is sent again if it was refused, failed three times, was recorded by social:baseline, or was cancelled or failed in Quiet Social.

It never publishes twice a post that is still scheduled or already published, and the networks the model skips stay skipped. A model not saved yet throws InvalidSocialConfiguration: the synchronisation reads the model from the database.

Cancelling

$article->cancelSocialPublication();

Cancels the active post of the model if it has not left yet. It is synchronous: the call reaches the API before the method returns. It takes the lock of the model, waits lock_wait seconds for it, and throws a LockTimeoutException if a synchronisation holds it longer; an API error surfaces as an SDK exception.

The next save sends the post again while the condition of the model holds: make the condition false to keep it unpublished.

Previewing

use QuietSocial\Sdk\Network;

$post = $article->toSocialPost();

$post->content;                                   // the common text
$post->network(Network::LinkedIn)?->content;      // the LinkedIn text, if it has its own
$post->scheduledAt;                               // null when it would leave now

Builds the SDK Post the model describes, without any call to the API and without its targets: a preview, for an edit screen or a test. A cover on a disk is read; a URL is not downloaded. A badly described model throws InvalidSocialConfiguration, invalid data throws InvalidSocialPost.

foreach ($article->socialPublications as $link) {
    $link->status;                  // scheduled, published, rejected, baseline…
    $link->remote_publication_id;   // pub_…, or null for a refused post
}

socialPublications lists the links of the model, kept up to date by webhooks: status, remote_publication_id, scheduled_at, published_at, fingerprint (null for a manual publication), last_error (JSON, for a rejected or failed link), closed_reason and cancelled_at. Its dates are stored in the timezone of your application.

Besides the statuses of the API, a link can be creating (an attempt in progress), baseline (recorded by social:baseline, never sent), rejected (refused, without a remote publication) or failed (did not leave, sent again on the next change).