Skip to content

Commit

Permalink
Make the POC a library for extensions (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 authored Feb 6, 2023
2 parents 952034d + 8f3c060 commit c9e5983
Show file tree
Hide file tree
Showing 16 changed files with 4,562 additions and 468 deletions.
16 changes: 16 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name-template: v$NEXT_PATCH_VERSION
tag-template: v$NEXT_PATCH_VERSION
categories:
- title: 🔨 Improvements
label: enhancement
- title: 🐛 Bug Fixes
label: bug
- title: 🚀 New Features
label: Feature
change-template: '- #$NUMBER: $TITLE by @$AUTHOR'
template: |
# Changes
$CHANGES
118 changes: 118 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: PHP tests
on: [push, pull_request]
jobs:
php-linter:
name: PHP Syntax check 5.6|7.2|7.3|8.0|8.1
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@master
with:
folder-to-exclude: "! -path \"./tests/*\""

- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master

- name: PHP syntax checker 8.0
uses: prestashop/github-action-php-lint/8.0@master

- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache

- run: composer install

- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix --diff --dry-run

phpstan:
name: PHPStan
runs-on: ubuntu-latest
strategy:
matrix:
prestashop_version: [
"https://github.com/PrestaShop/PrestaShop/releases/download/8.0.0/prestashop_8.0.0.zip",
"https://github.com/PrestaShop/PrestaShop/releases/download/1.7.4.4/prestashop_1.7.4.4.zip",
]
steps:
- name: Download PrestaShop code source
run: |
wget -O /tmp/prestashop.zip ${{ matrix.prestashop_version }}
unzip -o /tmp/prestashop.zip -d /tmp
unzip -o /tmp/prestashop.zip -d /tmp/prestashop
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- name: Checkout
uses: actions/checkout@v2

- name: Cache vendor folder
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- name: Cache composer folder
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-cache

- run: composer install

- name: Run PHPStan
env:
_PS_ROOT_DIR_: /tmp/prestashop
run: vendor/bin/phpstan

phpunit:
name: PHPUnit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache vendor folder
uses: actions/cache@v3
with:
path: vendor
key: php-${{ hashFiles('composer.lock') }}

- name: Cache composer folder
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: php-composer-cache

- name: Install dependencies
run: composer install

- name: PHPUnit tests 1.7
run: DOCKER_INTERNAL="1.7" make phpunit

- name: PHPUnit tests with PS 8
run: DOCKER_INTERNAL=8 make phpunit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/vendor/
.php-cs-fixer.cache
.phpunit.result.cache
12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$config = new PrestaShop\CodingStandards\CsFixer\Config();

$config
->setUsingCache(true)
->getFinder()
->in(__DIR__)
->exclude('translations')
->exclude('vendor');

return $config;
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
DOCKER_INTERNAL ?= 8
DOCKER = $(shell docker ps 2> /dev/null)

check-docker:
ifndef DOCKER
$(error "DOCKER is unavailable on your system")
endif

phpunit: check-docker
docker pull prestashop/docker-internal-images:${DOCKER_INTERNAL}
@docker run --rm \
--name phpunit \
-e PS_DOMAIN=localhost \
-e PS_ENABLE_SSL=0 \
-e PS_DEV_MODE=1 \
-e XDEBUG_MODE=coverage \
-e XDEBUG_ENABLED=1 \
-v ${PWD}:/var/www/html/test-lib \
-w /var/www/html/test-lib \
prestashop/docker-internal-images:${DOCKER_INTERNAL} \
sh -c " \
service mariadb start && \
service apache2 start && \
_PS_ROOT_DIR_=/var/www/html/ vendor/bin/phpunit \
"
@echo phpunit passed
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,60 @@
# module-lib-mbo-installer
A helper to ease the PS MBO download and unzip of modules from the Addons Marketplace : https://github.com/PrestaShopCorp/ps_mbo
# PrestaShop module library for MBO dependency

A helper to ease the download of [PS MBO (Marketplace in the Back Office)](https://github.com/PrestaShopCorp/ps_mbo) from the marketplace.
Starting from PrestaShop v8 a shop can be installed without any additional component, including a link to the marketplace. In this kind of installation, no additional module can be installed without being manually uploaded by the merchant on the modules page.

For extensions requiring other modules available on the marketplace on PrestaShop 8 Open Source, MBO should be installed first to make sure archives are found and can be downloaded on the marketplace.

## Installation

```
composer require prestashop/module-lib-mbo-adapter
```

## Version Guidance

| Version | Status | Packagist -| Namespace | Repo | Docs | PHP Version |
|---------|----------------|----------------------|--------------|---------------------|---------------------|--------------|
| 1.x | Latest | `prestashop/module-lib-mbo-adapter` | `Prestashop\ModuleLibMboInstaller` | [v1.x][lib-1-repo] | N/A | >=5.6 |

[lib-1-repo]: https://github.com/PrestaShopCorp/module-lib-mbo-installer/tree/main

## Usage

Actions and messages can be triggered if the module is missing from the shop.
This example would be called from your module.

### Retrieve details about module MBO

```php
$mboStatus = (new Prestashop\ModuleLibMboInstaller\Presenter)->present();

var_dump($mboStatus);
/*
Example output:
array(4) {
["isPresentOnDisk"]=>
bool(false)
["isInstalled"]=>
bool(false)
["isEnabled"]=>
bool(false)
["version"]=>
NULL
}
/*
```

### Trigger download and installation of MBO

Because we cannot provide additional endpoints on PrestaShop's router, you have to implement you own controller/route to trigger the installation.

```php
try {
$mboInstaller = new Prestashop\ModuleLibMboInstaller\Installer(_PS_VERSION_);
/** @var boolean */
$result = $mboInstaller->installModule();
} catch (\Exception $e) {
// Some errors can happen, i.e during initialization or download of the module
}
```
31 changes: 19 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
{
"name": "prestashop/addons_helper",
"type": "library",
"name": "prestashop/module-lib-mbo-installer",
"description": "A helper to ease the download PS MBO from the Addons Marketplace",
"license": "AFL-3.0",
"require": {
"prestashop/module-lib-guzzle-adapter": "^0.5.0"
"php": ">=5.6",
"prestashop/module-lib-guzzle-adapter": "^0.6"
},
"config": {
"platform": {
"php": "7.4.33"
}
},
"autoload": {
"psr-4": {
"Prestashop\\AddonsHelper\\": "src/"
"Prestashop\\ModuleLibMboInstaller\\": "src/"
}
},
"authors": [
{
"name": "PrestaShop SA",
"email": "[email protected]"
},
{
"name": "Mikatux",
"email": "[email protected]"
}
],
"config": {
"preferred-install": "dist",
"classmap-authoritative": true,
"optimize-autoloader": true,
"prepend-autoloader": false,
"platform": {
"php": "7.3"
}
"require-dev": {
"phpunit/phpunit": "^9.5|^8.5|^5.7",
"prestashop/php-dev-tools": "^4.2|^3.16",
"phpstan/phpstan": "^1.9"
}
}
Loading

0 comments on commit c9e5983

Please sign in to comment.