trypost/app/Services/Social/LinkedInPagePublisher.php
Paulo Castellano 29e90c52af
fix: LinkedIn company page post URL missing the post ID (#272)
* fix: LinkedIn company page post URL missing the post ID

LinkedInPagePublisher::postUrl() built a company/{username}/posts/
URL but never interpolated $postId into it, so the "view on LinkedIn"
link for company page posts always ended at the trailing slash.

Per LinkedIn's Posts API docs, the correct public URL for any
published post (member or organization) is always
feed/update/{postId} — so the override is removed and the class now
inherits the correct base implementation.

Closes #271

* address code review: backfill historical URLs, fix stale docblock, close test gaps

- Add social:backfill-linkedin-page-post-urls to recompute platform_url
  for LinkedIn Page posts published before the fix, whose broken
  company/{username}/posts/ URL was already persisted and never
  recomputed. Supports --dry-run.
- Fix AbstractLinkedInPublisher::postUrl() docblock, which still
  claimed company pages override it after the override was removed.
- LinkedInPagePublisherTest: assert result['url'] in the image and
  carousel publish tests (previously only asserted result['id']);
  add a null-postId case; collapse the two username-branch tests
  (now dead code) into one dataset-driven test plus a dedicated
  null-postId test.
2026-08-11 12:36:14 -03:00

34 lines
875 B
PHP

<?php
declare(strict_types=1);
namespace App\Services\Social;
use App\Enums\SocialAccount\Platform;
use App\Exceptions\Social\ErrorCategory;
use App\Exceptions\Social\LinkedInPublishException;
/**
* Publishes posts to a LinkedIn company page on behalf of an administering member.
*/
class LinkedInPagePublisher extends AbstractLinkedInPublisher
{
protected function platform(): Platform
{
return Platform::LinkedInPage;
}
protected function authorUrn(): string
{
$organizationId = $this->account->meta['organization_id'] ?? null;
if (! $organizationId) {
throw new LinkedInPublishException(
userMessage: 'LinkedIn Page organization ID not configured',
category: ErrorCategory::Permission,
);
}
return "urn:li:organization:{$organizationId}";
}
}