Skip to content

Commit

Permalink
Fix importing URLs with custom slugs from bitly
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Apr 12, 2024
1 parent d0c3607 commit 5e62f16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [5.3.2] - 2024-04-12
### Added
* *Nothing*

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* Take into consideration `custom_bitlinks` when consuming Bitly API.

When custom slugs are used, they are returned there, while the `link` field contains an internal random link which is not the one you want to import.


## [5.3.1] - 2024-03-28
### Added
* *Nothing*
Expand Down
2 changes: 1 addition & 1 deletion src/Sources/Bitly/BitlyApiImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function loadUrlsForGroup(
$date = $hasCreatedDate && $params->keepCreationDate
? DateHelper::dateFromAtom($link['created_at'])
: clone $progressTracker->startDate();
$parsedLink = $this->parseLink($link['link'] ?? '');
$parsedLink = $this->parseLink($link['custom_bitlinks'][0] ?? $link['link'] ?? '');
$host = $parsedLink['host'] ?? null;
$domain = $host !== 'bit.ly' && $params->importCustomDomains ? $host : null;
$shortCode = ltrim($parsedLink['path'] ?? '', '/');
Expand Down
4 changes: 3 additions & 1 deletion test/Sources/Bitly/BitlyApiImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function (string $uri) use (&$callCounts) {
[
'created_at' => '2020-04-01T00:00:00+0000',
'link' => 'http://customdom.com/ddd',
'custom_bitlinks' => [],
'long_url' => 'https://github.com',
'tags' => ['bar'],
],
Expand All @@ -90,7 +91,8 @@ function (string $uri) use (&$callCounts) {
],
[
'created_at' => '2020-02-01T00:00:00+0000',
'link' => 'http://bit.ly/bbb',
'link' => 'http://bit.ly/this_should_be_ignored',
'custom_bitlinks' => ['http://bit.ly/bbb'],
'long_url' => 'https://github.com',
'tags' => ['foo', 'bar'],
],
Expand Down

0 comments on commit 5e62f16

Please sign in to comment.