Skip to content

Commit

Permalink
Chuck/dev/reset schema (#155)
Browse files Browse the repository at this point in the history
* fix: disable telescope for several commands including migrations

* feat: consolidated, rewritten, and simplified migrations

* tweak: enforce use of postgres, our only supported db

* tweak: use text instead of varchar

this is considered best practice in postgres, as there is absolutely no difference between text and varchar.  if a column size limit is critical, the constraint should be added separately.

* refactor: simplify all types, inline and fix ->timestamps()

* refactor: change all jsonb props to computed using Laravel's Attributes

* refactor: do all metadata rewrites on the fly instead of load time
  • Loading branch information
chuckadams authored Feb 1, 2025
1 parent 61005cd commit e90cfd5
Show file tree
Hide file tree
Showing 45 changed files with 914 additions and 1,419 deletions.
30 changes: 8 additions & 22 deletions app/Data/Props/PluginProps.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Carbon\CarbonImmutable;
use DateTimeInterface;
use Override;
use Spatie\LaravelData\Attributes\Validation\Between;
use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Attributes\Validation\Min;
Expand All @@ -16,17 +17,6 @@
final class PluginProps extends ModelProps
{
/**
* @param Optional|array<string, mixed>|null $ratings
* @param Optional|array<string, mixed>|null $banners
* @param Optional|array<string, mixed>|null $contributors
* @param Optional|array<string, mixed>|null $icons
* @param Optional|array<string, mixed>|null $source
* @param Optional|array<string, mixed>|null $requires_plugins
* @param Optional|array<string, mixed>|null $compatibility
* @param Optional|array<string, mixed>|null $screenshots
* @param Optional|array<string, mixed>|null $sections
* @param Optional|array<string, mixed>|null $versions
* @param Optional|array<string, mixed>|null $upgrade_notice
* @param Optional|array<string, mixed> $tags
* @param Optional|array<string, mixed>|null $ac_raw_metadata
*/
Expand Down Expand Up @@ -61,7 +51,6 @@ public function __construct(
public readonly Optional|string|null $author_profile,
#[Between(0, 100)]
public readonly Optional|int $rating,
public readonly Optional|array|null $ratings,
#[Min(0)]
public readonly Optional|int $num_ratings,
#[Min(0)]
Expand All @@ -75,13 +64,9 @@ public function __construct(
#[Url]
#[Max(1024)]
public readonly Optional|string|null $homepage,
public readonly Optional|array|null $banners,
#[Url]
#[Max(1024)]
public readonly Optional|string|null $donate_link,
public readonly Optional|array|null $contributors,
public readonly Optional|array|null $icons,
public readonly Optional|array|null $source,
#[Max(255)]
public readonly Optional|string|null $business_model,
#[Url]
Expand All @@ -96,12 +81,6 @@ public function __construct(
#[Url]
#[Max(1024)]
public readonly Optional|string|null $repository_url,
public readonly Optional|array|null $requires_plugins,
public readonly Optional|array|null $compatibility,
public readonly Optional|array|null $screenshots,
public readonly Optional|array|null $sections,
public readonly Optional|array|null $versions,
public readonly Optional|array|null $upgrade_notice,

// associations
public readonly Optional|array $tags, // TODO
Expand Down Expand Up @@ -148,4 +127,11 @@ public static function make(
];
return self::from($args);
}

#[Override] // empty override to narrow the return type (BaseData::from is not generic)
public static function from(
mixed ...$args,
): static {
return parent::from(...$args);
}
}
16 changes: 8 additions & 8 deletions app/Data/Props/ThemeProps.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Data\WpOrg\Author;
use Carbon\CarbonImmutable;
use Override;
use Spatie\LaravelData\Attributes\Validation\Between;
use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Attributes\Validation\Min;
Expand All @@ -17,10 +18,6 @@
final class ThemeProps extends ModelProps
{
/**
* @param Optional|array<string, mixed>|null $ratings
* @param Optional|array<string, mixed>|null $sections
* @param Optional|array<string, mixed>|null $versions
* @param Optional|array<string, mixed>|null $requires
* @param Optional|array<string, mixed> $tags
* @param Optional|array<string, mixed>|null $ac_raw_metadata
*/
Expand Down Expand Up @@ -49,7 +46,6 @@ public function __construct(
#[Url]
#[Max(1024)]
public readonly Optional|string|null $screenshot_url,
public readonly Optional|array|null $ratings,
#[Between(0, 100)]
public readonly Optional|int $rating,
#[Min(0)]
Expand All @@ -64,9 +60,6 @@ public function __construct(
#[Url]
#[Max(1024)]
public readonly Optional|string|null $homepage,
public readonly Optional|array|null $sections,
public readonly Optional|array|null $versions,
public readonly Optional|array|null $requires,
public readonly Optional|bool $is_commercial,
#[Url]
#[Max(1024)]
Expand Down Expand Up @@ -114,4 +107,11 @@ public static function make(
];
return self::from($args);
}

#[Override] // empty override to narrow the return type (BaseData::from is not generic)
public static function from(
mixed ...$args,
): static {
return parent::from(...$args);
}
}
5 changes: 3 additions & 2 deletions app/Data/WpOrg/Themes/ThemeUpdateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
public string $url,
public string $package,
public ?string $requires,
public string $requires_php,
public ?string $requires_php,
) {}

/**
Expand All @@ -29,7 +29,8 @@ public static function fromModel(Theme $theme): self
new_version: $theme->version,
url: $theme->download_link,
package: "downloadurl_placeholder{$theme->version}",
requires: $theme->requires['wordpress'] ?? null,
// requires: $theme->requires['wordpress'] ?? null, // XXX HUH? requires is always a string...
requires: $theme->requires,
requires_php: $theme->requires_php,
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Resources/Plugins/PluginResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function toArray(Request $request): array
'last_updated' => $plugin->last_updated?->format(self::LAST_UPDATED_DATE_FORMAT),
'added' => $plugin->added->format('Y-m-d'),
'homepage' => $plugin->homepage,
'tags' => $plugin->tags,
'tags' => $plugin->tagsArray(),
'donate_link' => $plugin->donate_link,
'requires_plugins' => $plugin->requires_plugins ?? [],
'requires_plugins' => $plugin->requires_plugins,
]);

return match ($request->query('action')) {
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Resources/Plugins/PluginUpdateResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public function toArray(Request $request): array
'new_version' => $this->resource['new_version'],
'url' => "https://wordpress.org/plugins/{$this->resource['slug']}/",
'package' => $this->resource['package'],
'icons' => $this->resource['icons'] ?? [],
'banners' => $this->resource['banners'] ?? [],
'icons' => $this->resource['icons'],
'banners' => $this->resource['banners'],
'banners_rtl' => $this->resource['banners_rtl'] ?? [],
'requires' => $this->resource['requires'],
'tested' => $this->resource['tested'],
Expand Down
43 changes: 2 additions & 41 deletions app/Http/Resources/ThemeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ThemeResource extends JsonResource
* download_link: string,
* tags: array<string, string>,
* versions: array<string, string>,
* requires: bool,
* requires: array<string, string>,
* requires_php: string,
* is_commercial: bool,
* external_support_url: string|bool,
Expand All @@ -50,7 +50,7 @@ public function toArray(Request $request): array
$author = $resource->author->toArray();
unset($author['id']);

$tags = $resource->tags;
$tags = $resource->tagsArray();
ksort($tags);

$screenshotBase = "https://wp-themes.com/wp-content/themes/{$resource->slug}/screenshot";
Expand Down Expand Up @@ -116,43 +116,4 @@ private function whenField(string $fieldName, $value, $default = null): mixed
}
return $this->when($include, $value);
}

// upstream code below -- we get sections and ratings and such already processed. Leaving commented for later reference.

// /** @return array<string, string> */
// private function getSections(): array
// {
// return $resource->sections ?? [];
// $sections = [];
// if (preg_match_all('|--theme-data-(.+?)-->(.*?)<!|ims', $resource->content ?? "", $matches)) {
// foreach ($matches[1] as $i => $section) {
// $sections[$section] = trim($matches[2][$i]);
// }
// } else {
// $sections['description'] = $this->fixMangledDescription(trim($resource->content ?? ""));
// }
// return $sections;
// }
//
// /**
// * @param array<int>|null $ratings
// * @return Collection<string, int>
// */
// private function mapRatings(?array $ratings = []): Collection
// {
// return collect($ratings)
// ->mapWithKeys(fn($value, $key) => [(string) $key => $value]);
// }
//
// private function getDescription(): string
// {
// return strpos($resource->content ?? "", '<!--') !== false
// ? trim(substr($resource->content, 0, strpos($resource->content, '<!--')))
// : trim($resource->content);
// }
//
// private function fixMangledDescription(string $description): string
// {
// return str_replace(['[br]', '[p]'], ["\n", "\n\n"], $description);
// }
}
Loading

0 comments on commit e90cfd5

Please sign in to comment.