Skip to content

Commit

Permalink
[7.x] Statamic 5 (#1039)
Browse files Browse the repository at this point in the history
* Adjust version constraints

* Adjust minimum versions in docs

* Replace `array_pull` with `Arr:pull`

Statamic 5 drops the dependency on `laravel/helpers`, where this helper was coming from.

Swapped out for `Arr::pull()`

* Adjust Runway version constraint

* Use my proteus fork for now

* wip

* we dont really need to be testing against specific versions of testbench

* wip

* wip

* Replace `str_slug` with `Str::slug`

* Fix styling

* Simplify `TestCase`

* Add APP_KEY to PHPUnit configuration

* Fix Ignition

* Use the Runtime Antlers parser

* Fix styling

* Now that my Proteus PR is merged, switch back to the main package

* Change how we get a table's columns

The `doctrine/dbal` package was removed in Laravel 11, which meant the `getDoctrineSchemaManager` method was removed.

Instead, we can use `Schema::getColumns()` from laravel/framework#49020 , which was released in Laravel 10.34.

* Return a collection instead

* Adopt the new `casts` method

* Revert "Adopt the new `casts` method"

This reverts commit 22defdb.

* Database Orders docs: `doctrine/dbal` is no longer a dependency

* Remove check around whether `doctrine/dbal` is installed

* Use "real" v5 version constraint

* `AddonTestCase` has moved

* in fact, it has moved, but that release hasn't been tagged yet 🤦‍♂️

* use runway dev-master

---------

Co-authored-by: duncanmcclean <duncanmcclean@users.noreply.github.com>
  • Loading branch information
duncanmcclean and duncanmcclean authored Apr 13, 2024
1 parent 33ff0a3 commit 32b7ec4
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 170 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ jobs:

strategy:
matrix:
php: [8.1, 8.2, 8.3]
laravel: [10.*]
statamic: [^4.0]
testbench: [8.*]
php: [8.3, 8.2]
laravel: [11.*, 10.*]
statamic: [^5.0]
os: [ubuntu-latest]

name: ${{ matrix.php }} - ${{ matrix.statamic }} - ${{ matrix.laravel }}
Expand All @@ -33,11 +32,11 @@ jobs:

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "statamic/cms:${{ matrix.statamic }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "statamic/cms:${{ matrix.statamic }}" --no-interaction --no-update
composer install --no-interaction
- name: Run PHPUnit
run: composer test
run: vendor/bin/pest
env:
STRIPE_KEY: ${{ secrets.STRIPE_KEY }}
STRIPE_SECRET: ${{ secrets.STRIPE_SECRET }}
Expand Down
23 changes: 8 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"statamic": {
"name": "Simple Commerce",
"description": "A perfectly simple e-commerce addon for Statamic"
"description": "A simple, yet powerful e-commerce addon for Statamic."
},
"laravel": {
"providers": [
Expand All @@ -29,32 +29,25 @@
}
},
"require": {
"php": "^8.1",
"laravel/framework": "^10.0",
"php": "^8.2",
"laravel/framework": "^10.34 || ^11.0",
"mollie/mollie-api-php": "^2.30.0",
"moneyphp/money": "^4.0",
"paypal/paypal-checkout-sdk": "^1.0",
"pixelfear/composer-dist-plugin": "^0.1.0",
"statamic/cms": "^4.0",
"stillat/proteus": "^2.0",
"spatie/ignition": "^1.13",
"statamic/cms": "^5.0",
"stillat/proteus": "^3.0",
"stripe/stripe-php": "^7.7"
},
"require-dev": {
"statamic-rad-pack/runway": "^6.0.1",
"orchestra/testbench": "^8.0",
"statamic-rad-pack/runway": "dev-master",
"orchestra/testbench": "^8.0 || ^9.0",
"pestphp/pest": "^2.2",
"pestphp/pest-plugin-laravel": "^2.0",
"spatie/ray": "^1.17",
"spatie/test-time": "^1.3"
},
"scripts": {
"lint": [
"php-cs-fixer fix ./src"
],
"test": [
"php -d memory_limit=-1 -d max_execution_time=0 ./vendor/bin/pest"
]
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
Expand Down
6 changes: 2 additions & 4 deletions docs/database-orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ The following steps assume you already have a database setup. If you don't, plea

The process of switching your site to a database is painless, all you need to do is run a few commands, then you'll be golden.

First, you need to install [Runway](https://statamic.com/runway) & Doctrine DBAL.

Runway will let you view your customers & orders in the Control Panel and DBAL will help Simple Commerce understand your database (which is needed for [custom columns](#custom-columns)).
First, install [Runway](https://statamic.com/runway) which will let you manage your customers & orders in the Control Panel.

```sh
composer require statamic-rad-pack/runway doctrine/dbal
composer require statamic-rad-pack/runway
```

Next, run the "switch command". It'll copy the relevant database migrations, publish Runway's config file and update references in the Simple Commerce config:
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ To install Simple Commerce, there's two routes you can take. You can either [ins

To run Simple Commerce, your server (whether local or production) will need to meet the following requirements:

- PHP 8.2
- PHP 8.3
- Laravel 10
- [PHP `intl` extension](https://www.php.net/manual/en/book.intl.php)
- [Statamic CLI](https://github.com/statamic/cli)
- Some kind of web server (like [Laravel Valet](https://laravel.com/docs/master/valet))

And if you're installing into an existing site, your site must be on Statamic 3.3 (or higher) and Laravel 9 (or higher).
And if you're installing into an existing site, your site must be on Statamic 5 (or higher) and Laravel 10 (or higher).

## Installing with the Starter Kit

Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="base64:ybcI9MKuhLnESRSuWDfnJQuohOXMBaynfbTC5Y5i1FE="/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
Expand Down
4 changes: 0 additions & 4 deletions src/Console/Commands/SwitchToDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public function handle()
return $this->error('You need to install Runway before running this command. Run `composer require statamic-rad-pack/runway` first.');
}

if (! Composer::create()->isInstalled('doctrine/dbal')) {
return $this->error('You need to install Doctrine DBAL before running this command. Run `composer require doctrine/dbal` first.');
}

$this
->copyMigrationStubs()
->copyBlueprintStubs()
Expand Down
2 changes: 1 addition & 1 deletion src/Coupons/Coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public function discountText(): string

public function path()
{
return Stache::store('simple-commerce-coupons')->directory().str_slug($this->code()).'.yaml';
return Stache::store('simple-commerce-coupons')->directory().Str::slug($this->code()).'.yaml';
}

public function fileData()
Expand Down
8 changes: 4 additions & 4 deletions src/Coupons/CouponStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public function makeItemFromFile($path, $contents)
{
$data = YAML::file($path)->parse($contents);

if (! $id = array_pull($data, 'id')) {
if (! $id = Arr::pull($data, 'id')) {
$idGenerated = true;
$id = app('stache')->generateId();
}

$coupon = Coupon::make()
->id($id)
->code(array_pull($data, 'code'))
->type(array_pull($data, 'type'))
->value(array_pull($data, 'value'))
->code(Arr::pull($data, 'code'))
->type(Arr::pull($data, 'type'))
->value(Arr::pull($data, 'value'))
->data(Arr::except($data, ['code', 'type', 'value']));

if (isset($idGenerated)) {
Expand Down
14 changes: 4 additions & 10 deletions src/Customers/EloquentCustomerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,10 @@ public function delete(Customer $customer): void
*/
protected function getCustomColumns(): array
{
$tableColumns = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns((new $this->model)->getTable());

return collect($tableColumns)
->reject(function (Column $column) {
return in_array($column->getName(), $this->knownColumns);
})
->map->getName()
->toArray();
return collect(Schema::getColumns((new $this->model)->getTable()))
->reject(fn (array $column) => in_array($column['name'], $this->knownColumns))
->map(fn (array $column) => $column['name'])
->all();
}

public static function bindings(): array
Expand Down
8 changes: 3 additions & 5 deletions src/Customers/EloquentQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ protected function column($column)
protected function columnExists(string $column): bool
{
$databaseColumns = Blink::once("DatabaseColumns_{$this->builder->getModel()->getTable()}", function () {
$columns = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns($this->builder->getModel()->getTable());

return collect($columns)->map->getName()->values();
return collect(Schema::getColumns($this->builder->getModel()->getTable()))
->map(fn (array $column) => $column['name'])
->values();
});

return $databaseColumns->contains($column);
Expand Down
5 changes: 3 additions & 2 deletions src/Customers/EntryCustomerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DuncanMcClean\SimpleCommerce\Exceptions\CustomerNotFound;
use DuncanMcClean\SimpleCommerce\SimpleCommerce;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Statamic\Facades\Entry;
use Statamic\Facades\Stache;

Expand Down Expand Up @@ -57,7 +58,7 @@ public function findByEmail(string $email): ?Customer
{
$entry = Entry::query()
->where('collection', $this->collection)
->where('slug', str_slug($email))
->where('slug', Str::slug($email))
->first();

if (! $entry) {
Expand Down Expand Up @@ -105,7 +106,7 @@ public function save(Customer $customer): void
if ($customer->get('slug')) {
$entry->slug($customer->get('slug'));
} else {
$entry->slug(str_slug($customer->email()));
$entry->slug(Str::slug($customer->email()));
}

if ($customer->get('published')) {
Expand Down
6 changes: 3 additions & 3 deletions src/Exceptions/CurrencyFormatterNotWorking.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace DuncanMcClean\SimpleCommerce\Exceptions;

use Exception;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
use Spatie\Ignition\Contracts\BaseSolution;
use Spatie\Ignition\Contracts\ProvidesSolution;
use Spatie\Ignition\Contracts\Solution;

class CurrencyFormatterNotWorking extends Exception implements ProvidesSolution
{
Expand Down
6 changes: 3 additions & 3 deletions src/Exceptions/GatewayDoesNotExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace DuncanMcClean\SimpleCommerce\Exceptions;

use Exception;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
use Spatie\Ignition\Contracts\BaseSolution;
use Spatie\Ignition\Contracts\ProvidesSolution;
use Spatie\Ignition\Contracts\Solution;

class GatewayDoesNotExist extends Exception implements ProvidesSolution
{
Expand Down
6 changes: 3 additions & 3 deletions src/Exceptions/GatewayNotProvided.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace DuncanMcClean\SimpleCommerce\Exceptions;

use Exception;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
use Spatie\Ignition\Contracts\BaseSolution;
use Spatie\Ignition\Contracts\ProvidesSolution;
use Spatie\Ignition\Contracts\Solution;

class GatewayNotProvided extends Exception implements ProvidesSolution
{
Expand Down
6 changes: 3 additions & 3 deletions src/Exceptions/SiteNotConfiguredException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace DuncanMcClean\SimpleCommerce\Exceptions;

use Exception;
use Facade\IgnitionContracts\BaseSolution;
use Facade\IgnitionContracts\ProvidesSolution;
use Facade\IgnitionContracts\Solution;
use Spatie\Ignition\Contracts\BaseSolution;
use Spatie\Ignition\Contracts\ProvidesSolution;
use Spatie\Ignition\Contracts\Solution;

class SiteNotConfiguredException extends Exception implements ProvidesSolution
{
Expand Down
3 changes: 2 additions & 1 deletion src/Fieldtypes/GatewayFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use DuncanMcClean\SimpleCommerce\Support\Runway;
use Statamic\Facades\Action;
use Statamic\Fields\Fieldtype;
use Statamic\Support\Arr;

class GatewayFieldtype extends Fieldtype
{
Expand Down Expand Up @@ -95,7 +96,7 @@ public function augment($value)
}

return array_merge($gateway, [
'data' => array_pull($value, 'data', []),
'data' => Arr::pull($value, 'data', []),
]);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Listeners/SendConfiguredNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Support\Str;
use ReflectionClass;
use ReflectionParameter;
use Statamic\View\Antlers\Parser;
use Statamic\Facades\Antlers;

class SendConfiguredNotifications implements ShouldQueue
{
Expand Down Expand Up @@ -100,9 +100,7 @@ protected function getNotifiables(array $config, $notification, $event): ?array
return [
[
'channel' => 'mail',
'route' => (new Parser)
->parse($config['to'], $event->order->toAugmentedArray())
->__toString(),
'route' => (string) Antlers::parse($config['to'], $event->order->toAugmentedArray()),
],
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/Orders/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DuncanMcClean\SimpleCommerce\Countries;
use DuncanMcClean\SimpleCommerce\Regions;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class Address
{
Expand Down Expand Up @@ -95,7 +96,7 @@ public function region(): ?array
}

return [
'id' => str_slug(static::$region),
'id' => Str::slug(static::$region),
'name' => static::$region,
'country_iso' => static::$country,
];
Expand Down
14 changes: 4 additions & 10 deletions src/Orders/EloquentOrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,10 @@ public function delete($order): void
*/
protected function getCustomColumns(): array
{
$tableColumns = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns((new $this->model)->getTable());

return collect($tableColumns)
->reject(function (Column $column) {
return in_array($column->getName(), $this->knownColumns);
})
->map->getName()
->toArray();
return collect(Schema::getColumns((new $this->model)->getTable()))
->reject(fn (array $column) => in_array($column['name'], $this->knownColumns))
->map(fn (array $column) => $column['name'])
->all();
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Orders/EloquentQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ public function whereStatusLogDate(OrderStatus|PaymentStatus $status, Carbon $da
protected function columnExists(string $column): bool
{
$databaseColumns = Blink::once("DatabaseColumns_{$this->builder->getModel()->getTable()}", function () {
$columns = Schema::getConnection()
->getDoctrineSchemaManager()
->listTableColumns($this->builder->getModel()->getTable());

return collect($columns)->map->getName()->values();
return collect(Schema::getColumns($this->builder->getModel()->getTable()))
->map(fn (array $column) => $column['name'])
->values();
});

return $databaseColumns->contains($column);
Expand Down
7 changes: 4 additions & 3 deletions src/Tax/Standard/Stache/TaxCategory/TaxCategoryStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use DuncanMcClean\SimpleCommerce\Facades\TaxCategory;
use Statamic\Facades\YAML;
use Statamic\Stache\Stores\BasicStore;
use Statamic\Support\Arr;

class TaxCategoryStore extends BasicStore
{
Expand All @@ -17,17 +18,17 @@ public function makeItemFromFile($path, $contents)
{
$data = YAML::file($path)->parse($contents);

if (! $id = array_pull($data, 'id')) {
if (! $id = Arr::pull($data, 'id')) {
$idGenerated = true;
$id = app('stache')->generateId();
}

$taxCategory = TaxCategory::make()
->id($id)
->name(array_pull($data, 'name'));
->name(Arr::pull($data, 'name'));

if (isset($data['description'])) {
$taxCategory->description(array_pull($data, 'description'));
$taxCategory->description(Arr::pull($data, 'description'));
}

if (isset($idGenerated)) {
Expand Down
Loading

0 comments on commit 32b7ec4

Please sign in to comment.