diff --git a/README.md b/README.md index b05dacd..2c53aab 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 3. Build and start docker container `docker compose up -d` 4. Run `docker compose exec php-app php console.php app:migrate` file to create `database.sqlite` and create tables. 5. Run `docker compose exec php-app php console.php app:scrape` command to scrape all the products from the ryobi website. -6. Access web interface using `localhost:9000` address in web browser. +6. Access web interface using `localhost:9001` address in web browser. ## Update project @@ -16,6 +16,13 @@ 2. Run `git pull` 3. Start and build image in one go with command: `docker compose up -d --build --force-recreate` +## Running Cron + +For now only way of running `app:scrape` command on schedule is to use host crontab. +1. Run `crontab -e` command to edit host crontab job file +2. Add a new line with e.g. line like this `0 1 * * * cd /var/project/directory/ && docker compose exec php-app php console.php app:scrape` +3. Save and exit file editor. Cron will execute `app:scrape` once per day. + ## Screenshots ### Main screen of the web view diff --git a/docker-compose.yml b/docker-compose.yml index c93684e..5639a00 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,6 @@ services: php-app: + restart: unless-stopped build: . volumes: - .:/usr/src/app diff --git a/src/Controller/ProductController.php b/src/Controller/ProductController.php index eddeba5..32189ba 100644 --- a/src/Controller/ProductController.php +++ b/src/Controller/ProductController.php @@ -8,7 +8,11 @@ final class ProductController extends BaseController { public function __invoke(int $productId): void { - $product = Product::with('price')->find($productId); - $this->twig->display('product.html.twig', ['product' => $product ?? []]); + $product = Product::with([ + 'price' => fn($query) => $query->orderBy('created_at', 'desc') + ])->find($productId); + $priceList = $product->price()->pluck('price')->implode(','); + $priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->implode("','"); + $this->twig->display('product.html.twig', ['product' => $product ?? [], 'price_list' => $priceList, 'price_dates' => $priceDates]); } } diff --git a/src/templates/product.html.twig b/src/templates/product.html.twig index 68f72b2..b8c55e6 100644 --- a/src/templates/product.html.twig +++ b/src/templates/product.html.twig @@ -4,8 +4,8 @@
| {% if product.starred %}★{% else %} ☆ {% endif %} | -{{ product.name }} | +{{ product.name }} | {{ product.subTitle }} | link | |||
|
+
+
+
+ |
+ |||||||
|
| |||||||
| {% if product.starred %}★{% else %} ☆ {% endif %} | -{{ product.name }} | +{{ product.name }} | {{ product.subTitle }} | ||||