Release 0.245: refactor articles list and update package

This commit is contained in:
2026-02-08 01:35:13 +01:00
parent 4aea594477
commit d709a3df7b
28 changed files with 936 additions and 339 deletions

View File

@@ -21,7 +21,7 @@ ErrorDocument 404 /index.php
RewriteCond %{REQUEST_URI} !^(.*)/libraries/(.*) [NC]
RewriteCond %{REQUEST_URI} !^(.*)/layout/(.*) [NC]
RewriteRule ^admin/([^/]*)/([^/]*)/(.*)$ admin/index.php?module=$1&action=$2&$3 [L]
RewriteRule ^admin/([^/]*)/([^/]*)/(.*)$ admin/index.php?module=$1&action=$2&$3 [QSA,L]
RewriteRule ^admin/$ admin/index.php [L]
@@ -278,6 +278,6 @@ RewriteRule ^en/tytul-en$ index.php?article=13&lang=en&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-lsphp83 /opt/alt/php83 usr/bin/lsphp
</FilesMatch>
# <FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
# SetHandler application/x-lsphp83 /opt/alt/php83 usr/bin/lsphp
# </FilesMatch>

View File

@@ -250,6 +250,18 @@ tests/
## Ostatnie modyfikacje
### 2026-02-07: Usuniecie legacy kontrolera Articles (ver. 0.246)
- **UPDATE:** usunieto `autoload/admin/controls/class.Articles.php`
- **UPDATE:** `admin\Controllers\ArticlesController::galleryOrderSave()` uzywa `Domain\Article\ArticleRepository::saveGalleryOrder()`
- **UPDATE:** `Domain\Article\ArticleRepository` - dodano `saveGalleryOrder(int $articleId, string $order): bool`
- **UPDATE:** `admin\factory\Articles::gallery_order_save()` deleguje do `ArticleRepository::saveGalleryOrder()` (backward compatibility)
- **FIX:** sortowanie list admin po reloadzie - `RewriteRule` dla `/admin/...` ma `QSA`
- **FIX:** generator `\S::htacces()` komentuje dyrektywy `AddHandler|SetHandler|ForceType` (kompatybilnosc hostingu)
- **UPDATE:** zrodlo generatora `libraries/htaccess.conf` dostosowane do powyzszych zmian
- **WAZNE (deploy):** w paczce aktualizacji dodac `ver_X.XXX_files.txt` z wpisem:
`F: ../autoload/admin/controls/class.Articles.php`
- Testy: 65 tests, 131 assertions
### 2026-02-06: Migracja Articles::article_delete do DI (ver. 0.245)
- **UPDATE:** `Domain\Article\ArticleRepository` - dodano `archive()` (ustawia status = -1)
- **UPDATE:** `admin\Controllers\ArticlesController` - nowa akcja `delete()` z DI
@@ -324,5 +336,5 @@ tests/
- Metoda `clear_product_cache()` w klasie S
---
*Dokument aktualizowany: 2026-02-06*
*Dokument aktualizowany: 2026-02-07*

View File

@@ -195,6 +195,24 @@ grep -r "Product::getQuantity" .
- Kompatybilnosc: `admin\factory\Articles::articles_set_archive()` deleguje do repozytorium
- Testy: 2 nowe testy archive (success, failure)
- Aktualizacja: ver. 0.245
- ✅ ArticlesController::browseList() - **ZMIGROWANE** (2026-02-07) 🎉
- Nowa metoda kontrolera: `browseList()` (DI, instancyjna)
- Zmigrowana akcja: `browse_list` -> `browseList` (mapowanie w `admin\Site::$actionMap`)
- Legacy cleanup: usuniety `autoload/admin/controls/class.Articles.php` (brak fallback dla modułu Articles)
- Testy: 2 nowe testy kontraktu kontrolera (method exists + return type)
- ✅ ArticlesController::galleryOrderSave() - **ZMIGROWANE** (2026-02-07) 🎉
- Nowa metoda kontrolera: `galleryOrderSave()` (AJAX)
- Zmigrowana akcja: `gallery_order_save` -> `galleryOrderSave` (mapowanie w `admin\Site::$actionMap`)
- Implementacja: używa `Domain\Article\ArticleRepository::saveGalleryOrder()`
- Testy: 2 nowe testy kontraktu kontrolera (method exists + return type)
- ✅ Usuniecie legacy kontrolera Articles - **ZMIGROWANE** (2026-02-07) 🎉
- Usuniety plik: `autoload/admin/controls/class.Articles.php`
- Wymaganie dla aktualizacji: dodac wpis do `ver_X.XXX_files.txt`
- Wpis do usuniecia: `F: ../autoload/admin/controls/class.Articles.php`
- ✅ Stabilizacja generatora `.htaccess` - **ZMIGROWANE** (2026-02-07) 🎉
- FIX: regula admin ma `QSA` (query string dla sortowania/filtrow)
- FIX: `\S::htacces()` komentuje `AddHandler|SetHandler|ForceType` dla zgodnosci z hostingiem
- UPDATE: `libraries/htaccess.conf` zaktualizowany, aby poprawki nie znikaly po regeneracji
- **Settings** (migracja kontrolera - krok pośredni)
- ✅ SettingsRepository - **ZMIGROWANE** (2026-02-05) 🎉
@@ -327,4 +345,4 @@ vendor/bin/phpstan analyse autoload/Domain
---
*Rozpoczęto: 2025-02-05*
*Ostatnia aktualizacja: 2026-02-06*
*Ostatnia aktualizacja: 2026-02-07*

View File

@@ -7,12 +7,14 @@
./test.bat # Windows CMD (z nazwami testów)
./test-simple.bat # Tylko kropki (szybki)
./test-debug.bat # Pełne szczegóły (debug)
./test.ps1 # PowerShell (autodetekcja PHP)
./test.sh # Git Bash
```
### Konkretny plik
```bash
./test.bat tests/Unit/Domain/Product/ProductRepositoryTest.php
./test.ps1 tests/Unit/admin/Controllers/ArticlesControllerTest.php
```
## Tryby wyświetlania

View File

@@ -14,6 +14,7 @@ Aktualizacje znajdują się w folderze `updates/0.XX/` gdzie XX oznacza dziesią
### Zasada pakowania plików
- Do paczek aktualizacji **nie dodajemy plików `*.md`** (dokumentacja jest tylko wewnętrzna/deweloperska).
- Do paczek aktualizacji **nie dodajemy `updates/changelog.php`** (to plik serwisowy po stronie repozytorium aktualizacji, nie runtime klienta).
- Do paczek aktualizacji **nie dodajemy głównego `.htaccess` z katalogu projektu** (ten plik wdrażamy osobno, poza ZIP aktualizacji).
## Procedura tworzenia nowej aktualizacji

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -827,7 +827,7 @@ body {
td {
border-color: $cHoverBackground;
a {
a:not(.btn) {
transition: .15s ease;
&:hover {
@@ -1726,7 +1726,7 @@ input:checked[type="checkbox"]:before {
text-align: right;
}
a {
a:not(.btn) {
color: $cBlue;
transition: .15s ease;
font-weight: 500;
@@ -1736,6 +1736,24 @@ input:checked[type="checkbox"]:before {
}
}
a.btn {
color: #fff;
&:hover,
&:focus {
color: #fff;
}
}
a.btn-default {
color: #000;
&:hover,
&:focus {
color: #000;
}
}
thead {
background-color: $cHoverBackground;

View File

@@ -1,115 +0,0 @@
<?php
global $gdb;
$grid = new \grid( 'pp_articles' );
$grid -> gdb_opt = $gdb;
$grid -> sql = 'SELECT *'
. 'FROM ( '
. 'SELECT '
. 'id, date_add, date_modify, status, '
. '( SELECT title FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = pa.id AND title != \'\' ORDER BY o ASC LIMIT 1 ) AS title, '
. '( SELECT login FROM pp_users AS pu WHERE pu.id = pa.modify_by ) AS user '
. 'FROM '
. 'pp_articles AS pa WHERE status != -1 '
. ') AS q1 '
. 'WHERE '
. '1=1 [where] '
. 'ORDER BY '
. '[order_p1] [order_p2]';
$grid -> sql_count = 'SELECT '
. 'COUNT(0) FROM ( '
. 'SELECT '
. 'id, date_add, date_modify, status, '
. '( SELECT title FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = pa.id AND title != \'\' ORDER BY o ASC LIMIT 1 ) AS title, '
. '( SELECT login FROM pp_users AS pu WHERE pu.id = pa.modify_by ) AS user '
. 'FROM '
. 'pp_articles AS pa WHERE status != -1 '
. ') AS q1 '
. 'WHERE '
. '1=1 [where] ';
$grid -> debug = true;
$grid -> order = [ 'column' => 'date_add', 'type' => 'DESC' ];
$grid -> search = [
[ 'name' => 'Tytuł', 'db' => 'title', 'type' => 'text' ],
[ 'name' => 'Aktywny', 'db' => 'status', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ],
[ 'name' => 'Data dodania', 'db' => 'date_add', 'type' => 'date_range' ],
[ 'name' => 'Data modyfikacji', 'db' => 'date_modify', 'type' => 'date_range' ]
];
$grid -> columns_view = [
[
'name' => 'Lp.',
'th' => [ 'class' => 'g-lp' ],
'td' => [ 'class' => 'g-center' ],
'autoincrement' => true
],
[
'name' => 'Tytuł',
'db' => 'title',
'sort' => true,
'php' => 'echo "[title]"; echo "<small class=\'text-muted\'>" . \admin\factory\Articles::article_pages( [id] ) . "</small>";'
],
[
'name' => 'Aktywny',
'db' => 'status',
'replace' => [ 'array' => [ 0 => '<span style="color: #FF0000;">nie</span>', 1 => 'tak' ] ],
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
'sort' => true
],
[
'name' => 'Data dodania',
'db' => 'date_add',
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 220px;' ],
'php' => 'echo date( "Y-m-d H:i", strtotime( "[date_add]" ) );'
],
[
'name' => 'Data modyfikacji',
'db' => 'date_modify',
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 220px;' ],
'php' => 'echo date( "Y-m-d H:i", strtotime( "[date_modify]" ) );'
],
[
'name' => 'Modyfikowany przez',
'db' => 'user',
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 220px;' ],
],
[
'name' => 'Akcja',
'db' => 'id',
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 120px;' ],
'php' => 'echo "<a href=\'#\' class=\'button\' url=\'/" . \admin\factory\Articles::article_url( [id] ) . "\'>wybierz</a>";'
]
];
echo $grid -> draw();
?>
<style type="text/css">
body.sb-top.sb-top-sm .navbar.navbar-fixed-top + #sidebar_left + #content_wrapper {
padding-top: 0;
}
</style>
<script type="text/javascript">
function getUrlParam(paramName)
{
var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i');
var match = window.location.search.match(reParam);
return (match && match.length > 1) ? match[1] : '';
}
$( function()
{
$( '#sidebar_left, .navbar-fixed-top' ).hide();
var funcNum = getUrlParam('CKEditorFuncNum');
$( 'body' ).on( 'click', '.button', function()
{
window.opener.CKEDITOR.tools.callFunction(funcNum, $( this ).attr( 'url' ) );
window.close();
});
});
</script>

View File

@@ -1,100 +1,5 @@
<?php
global $gdb;
<?= \Tpl::view('components/table-list', ['list' => $this->viewModel]); ?>
$grid = new \grid( 'pp_articles' );
$grid -> gdb_opt = $gdb;
$grid -> sql = 'SELECT *'
. 'FROM ( '
. 'SELECT '
. 'id, date_add, date_modify, status, '
. '( SELECT title FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = pa.id AND title != \'\' ORDER BY o ASC LIMIT 1 ) AS title, '
. '( SELECT login FROM pp_users AS pu WHERE pu.id = pa.modify_by ) AS user '
. 'FROM '
. 'pp_articles AS pa WHERE status != -1 '
. ') AS q1 '
. 'WHERE '
. '1=1 [where] '
. 'ORDER BY '
. '[order_p1] [order_p2]';
$grid -> sql_count = 'SELECT '
. 'COUNT(0) FROM ( '
. 'SELECT '
. 'id, date_add, date_modify, status, '
. '( SELECT title FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = pa.id AND title != \'\' ORDER BY o ASC LIMIT 1 ) AS title, '
. '( SELECT login FROM pp_users AS pu WHERE pu.id = pa.modify_by ) AS user '
. 'FROM '
. 'pp_articles AS pa WHERE status != -1 '
. ') AS q1 '
. 'WHERE '
. '1=1 [where] ';
$grid -> debug = true;
$grid -> order = [ 'column' => 'date_add', 'type' => 'DESC' ];
$grid -> search = [
[ 'name' => 'Tytuł', 'db' => 'title', 'type' => 'text' ],
[ 'name' => 'Aktywny', 'db' => 'status', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ],
[ 'name' => 'Data dodania', 'db' => 'date_add', 'type' => 'date_range' ],
[ 'name' => 'Data modyfikacji', 'db' => 'date_modify', 'type' => 'date_range' ]
];
$grid -> columns_view = [
[
'name' => 'Lp.',
'th' => [ 'class' => 'g-lp' ],
'td' => [ 'class' => 'g-center' ],
'autoincrement' => true
],
[
'name' => 'Tytuł',
'db' => 'title',
'sort' => true,
'php' => 'echo "<a href=\'/admin/articles/article_edit/id=[id]\'>[title]</a>"; echo "<small class=\'text-muted\'>" . \admin\factory\Articles::article_pages( [id] ) . "</small>";'
],
[
'name' => 'Aktywny',
'db' => 'status',
'replace' => [ 'array' => [ 0 => '<span style="color: #FF0000;">nie</span>', 1 => 'tak' ] ],
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
'sort' => true
],
[
'name' => 'Data dodania',
'db' => 'date_add',
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 220px;' ],
'php' => 'echo date( "Y-m-d H:i", strtotime( "[date_add]" ) );'
],
[
'name' => 'Data modyfikacji',
'db' => 'date_modify',
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 220px;' ],
'php' => 'echo date( "Y-m-d H:i", strtotime( "[date_modify]" ) );'
],
[
'name' => 'Modyfikowany przez',
'db' => 'user',
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 220px;' ],
],
[
'name' => 'Edytuj',
'action' => [ 'type' => 'edit', 'url' => '/admin/articles/article_edit/id=[id]' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
'td' => [ 'class' => 'g-center' ]
],
[
'name' => 'Usuń',
'action' => [ 'type' => 'delete', 'url' => '/admin/articles/article_delete/id=[id]' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
'td' => [ 'class' => 'g-center' ]
]
];
$grid -> buttons = [
[
'label' => 'Dodaj artykuł',
'url' => '/admin/articles/article_edit/',
'icon' => 'fa-plus-circle',
'class' => 'btn-success'
]
];
echo $grid -> draw();
<?php if (!empty($this->viewModel->customScriptView)): ?>
<?= \Tpl::view($this->viewModel->customScriptView, ['list' => $this->viewModel]); ?>
<?php endif; ?>

View File

@@ -0,0 +1,219 @@
<?php
$list = $this->list;
$buildUrl = function(array $params = []) use ($list): string {
$query = array_merge($list->query, $params);
foreach ($query as $key => $value) {
if ($value === '' || $value === null) {
unset($query[$key]);
}
}
$qs = http_build_query($query);
return $list->basePath . ($qs ? ('?' . $qs) : '');
};
$currentSort = $list->sort['column'] ?? '';
$currentDir = strtoupper($list->sort['dir'] ?? 'DESC');
$page = max(1, (int)($list->pagination['page'] ?? 1));
$totalPages = max(1, (int)($list->pagination['total_pages'] ?? 1));
$total = (int)($list->pagination['total'] ?? 0);
$perPage = (int)($list->pagination['per_page'] ?? 15);
?>
<div class="panel">
<div class="panel-heading">
<div class="row">
<div class="col-sm-8">
<?php if (!empty($list->createUrl) && !empty($list->createLabel)): ?>
<a href="<?= htmlspecialchars($list->createUrl, ENT_QUOTES, 'UTF-8'); ?>" class="btn btn-success btn-sm">
<i class="fa fa-plus-circle mr5"></i><?= htmlspecialchars($list->createLabel, ENT_QUOTES, 'UTF-8'); ?>
</a>
<?php endif; ?>
</div>
<div class="col-sm-4 text-right">
<span class="text-muted">Wyników: <?= $total; ?></span>
</div>
</div>
</div>
<div class="panel-body">
<form method="get" action="<?= htmlspecialchars($list->basePath, ENT_QUOTES, 'UTF-8'); ?>" class="row mb15">
<?php foreach ($list->filters as $filter): ?>
<?php
$filterKey = (string)($filter['key'] ?? '');
$inputId = 'filter_' . preg_replace('/[^a-zA-Z0-9_]+/', '_', $filterKey);
?>
<div class="col-sm-2 mb10">
<label for="<?= htmlspecialchars($inputId, ENT_QUOTES, 'UTF-8'); ?>" class="control-label">
<?= htmlspecialchars((string)($filter['label'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>
</label>
<?php if (($filter['type'] ?? '') === 'select'): ?>
<select
id="<?= htmlspecialchars($inputId, ENT_QUOTES, 'UTF-8'); ?>"
name="<?= htmlspecialchars($filter['key'], ENT_QUOTES, 'UTF-8'); ?>"
class="form-control input-sm"
title="<?= htmlspecialchars($filter['label'], ENT_QUOTES, 'UTF-8'); ?>"
>
<?php foreach (($filter['options'] ?? []) as $value => $label): ?>
<option value="<?= htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); ?>"<?= ((string)($filter['value'] ?? '') === (string)$value) ? ' selected="selected"' : ''; ?>>
<?= htmlspecialchars((string)$label, ENT_QUOTES, 'UTF-8'); ?>
</option>
<?php endforeach; ?>
</select>
<?php elseif (($filter['type'] ?? '') === 'date'): ?>
<input
type="date"
id="<?= htmlspecialchars($inputId, ENT_QUOTES, 'UTF-8'); ?>"
name="<?= htmlspecialchars($filter['key'], ENT_QUOTES, 'UTF-8'); ?>"
value="<?= htmlspecialchars((string)($filter['value'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>"
class="form-control input-sm"
title="<?= htmlspecialchars($filter['label'], ENT_QUOTES, 'UTF-8'); ?>"
/>
<?php else: ?>
<input
type="text"
id="<?= htmlspecialchars($inputId, ENT_QUOTES, 'UTF-8'); ?>"
name="<?= htmlspecialchars($filter['key'], ENT_QUOTES, 'UTF-8'); ?>"
value="<?= htmlspecialchars((string)($filter['value'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>"
class="form-control input-sm"
placeholder="<?= htmlspecialchars($filter['label'], ENT_QUOTES, 'UTF-8'); ?>"
title="<?= htmlspecialchars($filter['label'], ENT_QUOTES, 'UTF-8'); ?>"
/>
<?php endif; ?>
</div>
<?php endforeach; ?>
<input type="hidden" name="sort" value="<?= htmlspecialchars((string)$currentSort, ENT_QUOTES, 'UTF-8'); ?>" />
<input type="hidden" name="dir" value="<?= htmlspecialchars((string)$currentDir, ENT_QUOTES, 'UTF-8'); ?>" />
<input type="hidden" name="per_page" value="<?= $perPage; ?>" />
<div class="col-sm-12">
<button type="submit" class="btn btn-primary btn-sm">Szukaj</button>
<a href="<?= htmlspecialchars($list->basePath, ENT_QUOTES, 'UTF-8'); ?>" class="btn btn-default btn-sm">Wyczyść</a>
</div>
</form>
<div class="table-responsive">
<table class="table table-hover table-striped table-bordered mbn">
<thead>
<tr>
<?php foreach ($list->columns as $column): ?>
<?php
$sortKey = (string)($column['sort_key'] ?? ($column['key'] ?? ''));
$isAllowedSortKey = empty($list->sortableColumns) || in_array($sortKey, $list->sortableColumns, true);
$isSortable = !empty($column['sortable']) && $sortKey !== '' && $isAllowedSortKey;
$isCurrent = $isSortable && $currentSort === $sortKey;
$nextDir = ($isCurrent && $currentDir === 'ASC') ? 'DESC' : 'ASC';
$sortUrl = $buildUrl([
'sort' => $sortKey,
'dir' => $nextDir,
'page' => 1,
]);
?>
<th class="<?= htmlspecialchars((string)($column['class'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>">
<?php if ($isSortable): ?>
<a href="<?= htmlspecialchars($sortUrl, ENT_QUOTES, 'UTF-8'); ?>">
<?= htmlspecialchars((string)($column['label'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>
<?php if ($isCurrent): ?>
<span aria-hidden="true"><?= $currentDir === 'ASC' ? '↑' : '↓'; ?></span>
<?php else: ?>
<span class="text-muted" aria-hidden="true">↕</span>
<?php endif; ?>
</a>
<?php else: ?>
<?= htmlspecialchars((string)($column['label'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>
<?php endif; ?>
</th>
<?php endforeach; ?>
<th class="text-center" style="width: 160px;">Akcje</th>
</tr>
</thead>
<tbody>
<?php if (is_array($list->rows) && !empty($list->rows)): ?>
<?php foreach ($list->rows as $row): ?>
<tr>
<?php foreach ($list->columns as $column): ?>
<?php
$key = $column['key'] ?? '';
$raw = !empty($column['raw']);
$value = $row[$key] ?? '';
?>
<td class="<?= htmlspecialchars((string)($column['class'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>">
<?php if ($raw): ?>
<?= (string)$value; ?>
<?php else: ?>
<?= htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); ?>
<?php endif; ?>
</td>
<?php endforeach; ?>
<td class="text-center">
<?php foreach (($row['_actions'] ?? []) as $action): ?>
<a
href="<?= htmlspecialchars((string)($action['url'] ?? '#'), ENT_QUOTES, 'UTF-8'); ?>"
class="<?= htmlspecialchars((string)($action['class'] ?? 'btn btn-default btn-xs'), ENT_QUOTES, 'UTF-8'); ?>"
<?php if (!empty($action['confirm'])): ?>
onclick="return confirm('<?= htmlspecialchars((string)$action['confirm'], ENT_QUOTES, 'UTF-8'); ?>');"
<?php endif; ?>
>
<?= htmlspecialchars((string)($action['label'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>
</a>
<?php endforeach; ?>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="<?= count($list->columns) + 1; ?>">
<div class="alert alert-danger mbn"><?= htmlspecialchars((string)$list->emptyMessage, ENT_QUOTES, 'UTF-8'); ?></div>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="row mt15">
<div class="col-sm-6">
<ul class="pagination">
<?php $prevPage = max(1, $page - 1); ?>
<?php $nextPage = min($totalPages, $page + 1); ?>
<li class="<?= $page <= 1 ? 'disabled' : ''; ?>">
<a href="<?= htmlspecialchars($buildUrl(['page' => 1]), ENT_QUOTES, 'UTF-8'); ?>"><i class="fa fa-fast-backward"></i></a>
</li>
<li class="<?= $page <= 1 ? 'disabled' : ''; ?>">
<a href="<?= htmlspecialchars($buildUrl(['page' => $prevPage]), ENT_QUOTES, 'UTF-8'); ?>"><i class="fa fa-backward"></i></a>
</li>
<?php for ($i = max(1, $page - 3); $i <= min($totalPages, $page + 3); $i++): ?>
<li class="<?= $i === $page ? 'active' : ''; ?>">
<a href="<?= htmlspecialchars($buildUrl(['page' => $i]), ENT_QUOTES, 'UTF-8'); ?>"><?= $i; ?></a>
</li>
<?php endfor; ?>
<li class="<?= $page >= $totalPages ? 'disabled' : ''; ?>">
<a href="<?= htmlspecialchars($buildUrl(['page' => $nextPage]), ENT_QUOTES, 'UTF-8'); ?>"><i class="fa fa-forward"></i></a>
</li>
<li class="<?= $page >= $totalPages ? 'disabled' : ''; ?>">
<a href="<?= htmlspecialchars($buildUrl(['page' => $totalPages]), ENT_QUOTES, 'UTF-8'); ?>"><i class="fa fa-fast-forward"></i></a>
</li>
</ul>
</div>
<div class="col-sm-6 text-right">
<form method="get" action="<?= htmlspecialchars($list->basePath, ENT_QUOTES, 'UTF-8'); ?>" class="form-inline">
<?php foreach ($list->query as $key => $value): ?>
<?php if ($key !== 'per_page' && $key !== 'page'): ?>
<input type="hidden" name="<?= htmlspecialchars((string)$key, ENT_QUOTES, 'UTF-8'); ?>" value="<?= htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); ?>" />
<?php endif; ?>
<?php endforeach; ?>
<input type="hidden" name="page" value="1" />
Wyświetlaj
<select name="per_page" class="form-control input-sm" onchange="this.form.submit()">
<?php foreach ($list->perPageOptions as $opt): ?>
<option value="<?= (int)$opt; ?>"<?= ((int)$opt === $perPage) ? ' selected="selected"' : ''; ?>><?= (int)$opt; ?></option>
<?php endforeach; ?>
</select>
rekordów
</form>
</div>
</div>
</div>
</div>

View File

@@ -6,6 +6,8 @@ namespace Domain\Article;
*/
class ArticleRepository
{
private const MAX_PER_PAGE = 100;
private $db;
public function __construct($db)
@@ -329,6 +331,159 @@ class ArticleRepository
return (bool)$result;
}
/**
* Zwraca liste artykulow do panelu admin z filtrowaniem, sortowaniem i paginacja.
*
* @return array{items: array<int, array<string, mixed>>, total: int}
*/
public function listForAdmin(
array $filters,
string $sortColumn = 'date_add',
string $sortDir = 'DESC',
int $page = 1,
int $perPage = 15
): array {
$sortColumn = trim($sortColumn);
$sortDir = strtoupper(trim($sortDir));
$allowedSortColumns = [
'title' => 'title',
'status' => 'pa.status',
'date_add' => 'pa.date_add',
'date_modify' => 'pa.date_modify',
'user' => 'user',
];
$sortSql = $allowedSortColumns[$sortColumn] ?? 'pa.date_add';
$sortDir = $sortDir === 'ASC' ? 'ASC' : 'DESC';
$page = max(1, $page);
$perPage = min(self::MAX_PER_PAGE, max(1, $perPage));
$offset = ($page - 1) * $perPage;
$where = ['pa.status != -1'];
$params = [];
$title = trim((string)($filters['title'] ?? ''));
if (strlen($title) > 255) {
$title = substr($title, 0, 255);
}
if ($title !== '') {
$where[] = "(
SELECT title
FROM pp_articles_langs AS pal, pp_langs AS pl
WHERE lang_id = pl.id AND article_id = pa.id AND title != ''
ORDER BY o ASC
LIMIT 1
) LIKE :title";
$params[':title'] = '%' . $title . '%';
}
if (($filters['status'] ?? '') !== '' && ($filters['status'] === '0' || $filters['status'] === '1')) {
$where[] = 'pa.status = :status';
$params[':status'] = (int)$filters['status'];
}
$this->appendDateRangeFilter($where, $params, 'pa.date_add', 'date_add_from', 'date_add_to', $filters);
$this->appendDateRangeFilter($where, $params, 'pa.date_modify', 'date_modify_from', 'date_modify_to', $filters);
$whereSql = implode(' AND ', $where);
$sqlCount = "
SELECT COUNT(0)
FROM pp_articles AS pa
WHERE {$whereSql}
";
$stmtCount = $this->db->query($sqlCount, $params);
$countRows = $stmtCount ? $stmtCount->fetchAll() : [];
$total = isset($countRows[0][0]) ? (int)$countRows[0][0] : 0;
$sql = "
SELECT
pa.id,
pa.date_add,
pa.date_modify,
pa.status,
(
SELECT title
FROM pp_articles_langs AS pal, pp_langs AS pl
WHERE lang_id = pl.id AND article_id = pa.id AND title != ''
ORDER BY o ASC
LIMIT 1
) AS title,
(
SELECT login
FROM pp_users AS pu
WHERE pu.id = pa.modify_by
) AS user
FROM pp_articles AS pa
WHERE {$whereSql}
ORDER BY {$sortSql} {$sortDir}, pa.id {$sortDir}
LIMIT {$perPage} OFFSET {$offset}
";
$stmt = $this->db->query($sql, $params);
$items = $stmt ? $stmt->fetchAll() : [];
return [
'items' => is_array($items) ? $items : [],
'total' => $total,
];
}
/**
* Zapisuje kolejnosc zdjec galerii artykulu.
*/
public function saveGalleryOrder(int $articleId, string $order): bool
{
$imageIds = explode(';', $order);
if (!is_array($imageIds) || empty($imageIds)) {
return true;
}
$position = 0;
foreach ($imageIds as $imageId) {
if ($imageId === '' || $imageId === null) {
continue;
}
$this->db->update('pp_articles_images', [
'o' => $position++,
], [
'AND' => [
'article_id' => $articleId,
'id' => (int)$imageId,
],
]);
}
return true;
}
private function appendDateRangeFilter(
array &$where,
array &$params,
string $column,
string $fromKey,
string $toKey,
array $filters
): void {
$from = trim((string)($filters[$fromKey] ?? ''));
$to = trim((string)($filters[$toKey] ?? ''));
if ($from !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $from)) {
$fromParam = ':' . str_replace('.', '_', $column) . '_from';
$where[] = "{$column} >= {$fromParam}";
$params[$fromParam] = $from . ' 00:00:00';
}
if ($to !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) {
$toParam = ':' . str_replace('.', '_', $column) . '_to';
$where[] = "{$column} <= {$toParam}";
$params[$toParam] = $to . ' 23:59:59';
}
}
/**
* Usuwa nieprzypisane pliki artykulow (article_id = null) wraz z plikami z dysku.
*/

View File

@@ -17,7 +17,123 @@ class ArticlesController
*/
public function list(): string
{
return \admin\view\Articles::articles_list();
$sortableColumns = ['title', 'status', 'date_add', 'date_modify'];
$filterDefinitions = [
[
'key' => 'title',
'label' => 'Tytul',
'type' => 'text',
],
[
'key' => 'status',
'label' => 'Aktywny',
'type' => 'select',
'options' => [
'' => '- aktywny -',
'1' => 'tak',
'0' => 'nie',
],
],
];
$listRequest = \admin\Support\TableListRequestFactory::fromRequest(
$filterDefinitions,
$sortableColumns,
'date_add'
);
$result = $this->repository->listForAdmin(
$listRequest['filters'],
$listRequest['sortColumn'],
$listRequest['sortDir'],
$listRequest['page'],
$listRequest['perPage']
);
$rows = [];
$lp = ($listRequest['page'] - 1) * $listRequest['perPage'] + 1;
foreach ($result['items'] as $item) {
$id = (int)$item['id'];
$title = (string)($item['title'] ?? '');
$pages = (string)\admin\factory\Articles::article_pages($id);
$rows[] = [
'lp' => $lp++ . '.',
'title' => '<a href="/admin/articles/article_edit/id=' . $id . '">' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</a>'
. '<small class="text-muted">' . htmlspecialchars($pages, ENT_QUOTES, 'UTF-8') . '</small>',
'status' => ((int)$item['status'] === 1) ? 'tak' : '<span style="color: #FF0000;">nie</span>',
'date_add' => !empty($item['date_add']) ? date('Y-m-d H:i', strtotime((string)$item['date_add'])) : '-',
'date_modify' => !empty($item['date_modify']) ? date('Y-m-d H:i', strtotime((string)$item['date_modify'])) : '-',
'user' => htmlspecialchars((string)($item['user'] ?? ''), ENT_QUOTES, 'UTF-8'),
'_actions' => [
[
'label' => 'Edytuj',
'url' => '/admin/articles/article_edit/id=' . $id,
'class' => 'btn btn-xs btn-primary',
],
[
'label' => 'Usun',
'url' => '/admin/articles/article_delete/id=' . $id,
'class' => 'btn btn-xs btn-danger',
'confirm' => 'Na pewno chcesz usunac wybrany element?',
],
],
];
}
$total = (int)$result['total'];
$totalPages = max(1, (int)ceil($total / $listRequest['perPage']));
$viewModel = new \admin\ViewModels\Common\PaginatedTableViewModel(
[
['key' => 'lp', 'label' => 'Lp.', 'class' => 'text-center', 'sortable' => false],
['key' => 'title', 'sort_key' => 'title', 'label' => 'Tytul', 'sortable' => true, 'raw' => true],
['key' => 'status', 'sort_key' => 'status', 'label' => 'Aktywny', 'class' => 'text-center', 'sortable' => true, 'raw' => true],
['key' => 'date_add', 'sort_key' => 'date_add', 'label' => 'Data dodania', 'class' => 'text-center', 'sortable' => true],
['key' => 'date_modify', 'sort_key' => 'date_modify', 'label' => 'Data modyfikacji', 'class' => 'text-center', 'sortable' => true],
['key' => 'user', 'sort_key' => 'user', 'label' => 'Modyfikowany przez', 'class' => 'text-center', 'sortable' => true],
],
$rows,
$listRequest['viewFilters'],
[
'column' => $listRequest['sortColumn'],
'dir' => $listRequest['sortDir'],
],
[
'page' => $listRequest['page'],
'per_page' => $listRequest['perPage'],
'total' => $total,
'total_pages' => $totalPages,
],
array_merge($listRequest['queryFilters'], [
'sort' => $listRequest['sortColumn'],
'dir' => $listRequest['sortDir'],
'per_page' => $listRequest['perPage'],
]),
$listRequest['perPageOptions'],
$sortableColumns,
'/admin/articles/view_list/',
'Brak danych w tabeli.',
'/admin/articles/article_edit/',
'Dodaj artykul'
);
return \Tpl::view('articles/articles-list', [
'viewModel' => $viewModel,
]);
}
/**
* Zapis kolejnosci galerii (AJAX)
*/
public function galleryOrderSave(): void
{
if ($this->repository->saveGalleryOrder((int)\S::get('article_id'), (string)\S::get('order'))) {
echo json_encode(['status' => 'ok', 'msg' => 'Artykul zostal zapisany.']);
}
exit;
}
/**
@@ -28,10 +144,10 @@ class ArticlesController
global $user;
$values = json_decode(\S::get('values'), true);
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania artykułu wystąpił błąd. Proszę spróbować ponownie.'];
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania artykulu wystapil blad. Prosze sprobowac ponownie.'];
if ($id = $this->repository->save((int)($values['id'] ?? 0), $values, (int)$user['id'])) {
$response = ['status' => 'ok', 'msg' => 'Artykuł został zapisany.', 'id' => $id];
$response = ['status' => 'ok', 'msg' => 'Artykul zostal zapisany.', 'id' => $id];
}
echo json_encode($response);
@@ -44,7 +160,7 @@ class ArticlesController
public function delete(): void
{
if ($this->repository->archive((int)\S::get('id'))) {
\S::alert('Artykuł został przeniesiony do archiwum.');
\S::alert('Artykul zostal przeniesiony do archiwum.');
}
header('Location: /admin/articles/view_list/');

View File

@@ -0,0 +1,100 @@
<?php
namespace admin\Support;
class TableListRequestFactory
{
public const DEFAULT_PER_PAGE_OPTIONS = [5, 10, 15, 25, 50, 100];
public const DEFAULT_PER_PAGE = 15;
/**
* Buduje kontekst listy (filtry, sortowanie, paginacja) z requestu.
*
* @return array{
* page:int,
* perPage:int,
* perPageOptions:array<int,int>,
* filters:array<string,string>,
* viewFilters:array<int,array<string,mixed>>,
* queryFilters:array<string,string>,
* sortColumn:string,
* sortDir:string
* }
*/
public static function fromRequest(
array $filterDefinitions,
array $sortableColumns,
string $defaultSortColumn = 'date_add',
?array $perPageOptions = null,
?int $defaultPerPage = null
): array {
if ($perPageOptions === null) {
$perPageOptions = self::DEFAULT_PER_PAGE_OPTIONS;
}
if ($defaultPerPage === null) {
$defaultPerPage = self::DEFAULT_PER_PAGE;
}
if (!in_array($defaultPerPage, $perPageOptions, true)) {
$defaultPerPage = (int)$perPageOptions[0];
}
$page = max(1, (int)\S::get('page'));
$perPage = (int)\S::get('per_page');
if (!in_array($perPage, $perPageOptions, true)) {
$perPage = $defaultPerPage;
}
$filters = [];
$viewFilters = [];
$queryFilters = [];
foreach ($filterDefinitions as $definition) {
$key = (string)($definition['key'] ?? '');
if ($key === '') {
continue;
}
$type = (string)($definition['type'] ?? 'text');
$value = (string)\S::get($key);
$filters[$key] = $value;
$queryFilters[$key] = $value;
$filterConfig = [
'key' => $key,
'label' => (string)($definition['label'] ?? $key),
'type' => $type,
'value' => $value,
];
if ($type === 'select' && isset($definition['options']) && is_array($definition['options'])) {
$filterConfig['options'] = $definition['options'];
}
$viewFilters[] = $filterConfig;
}
$sortColumn = trim((string)\S::get('sort'));
if (!in_array($sortColumn, $sortableColumns, true)) {
$sortColumn = $defaultSortColumn;
}
$sortDir = strtoupper(trim((string)\S::get('dir')));
if (!in_array($sortDir, ['ASC', 'DESC'], true)) {
$sortDir = 'DESC';
}
return [
'page' => $page,
'perPage' => $perPage,
'perPageOptions' => $perPageOptions,
'filters' => $filters,
'viewFilters' => $viewFilters,
'queryFilters' => $queryFilters,
'sortColumn' => $sortColumn,
'sortDir' => $sortDir,
];
}
}
?>

View File

@@ -0,0 +1,50 @@
<?php
namespace admin\ViewModels\Common;
class PaginatedTableViewModel
{
public array $columns;
public array $rows;
public array $filters;
public array $sort;
public array $pagination;
public array $query;
public array $perPageOptions;
public array $sortableColumns;
public string $basePath;
public string $emptyMessage;
public ?string $createUrl;
public ?string $createLabel;
public ?string $customScriptView;
public function __construct(
array $columns = [],
array $rows = [],
array $filters = [],
array $sort = [],
array $pagination = [],
array $query = [],
array $perPageOptions = [5, 10, 15, 25, 50, 100],
array $sortableColumns = [],
string $basePath = '',
string $emptyMessage = 'Brak danych.',
?string $createUrl = null,
?string $createLabel = null,
?string $customScriptView = null
) {
$this->columns = $columns;
$this->rows = $rows;
$this->filters = $filters;
$this->sort = $sort;
$this->pagination = $pagination;
$this->query = $query;
$this->perPageOptions = $perPageOptions;
$this->sortableColumns = $sortableColumns;
$this->basePath = $basePath;
$this->emptyMessage = $emptyMessage;
$this->createUrl = $createUrl;
$this->createLabel = $createLabel;
$this->customScriptView = $customScriptView;
}
}
?>

View File

@@ -253,6 +253,7 @@ class Site
* Potrzebne gdy stary routing używa innej konwencji nazw
*/
private static $actionMap = [
'gallery_order_save' => 'galleryOrderSave',
'view_list' => 'list',
'article_edit' => 'edit',
'article_save' => 'save',

View File

@@ -1,83 +0,0 @@
<?php
namespace admin\controls;
class Articles
{
public static function gallery_order_save()
{
if ( \admin\factory\Articles::gallery_order_save( \S::get( 'article_id' ), \S::get( 'order' ) ) )
echo json_encode( [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.' ] );
exit;
}
public static function browse_list()
{
return \admin\view\Articles::browse_list();
}
/**
* @deprecated Routing kieruje do admin\Controllers\ArticlesController::delete().
* Ta metoda pozostaje tylko jako fallback dla starej architektury.
*/
public static function article_delete()
{
if ( \admin\factory\Articles::articles_set_archive( \S::get( 'id' ) ) )
\S::alert( 'Artykuł został przeniesiony do archiwum.' );
header( 'Location: /admin/articles/view_list/' );
exit;
}
/**
* @deprecated Routing kieruje do admin\Controllers\ArticlesController::save().
* Ta metoda pozostaje tylko jako fallback dla starej architektury.
*/
public static function article_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania artykułu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\Articles::article_save(
$values['id'], $values['title'], $values['main_image'], $values['entry'], $values['text'], $values['table_of_contents'], $values['status'], $values['show_title'], $values['show_table_of_contents'], $values['show_date_add'], $values['date_add'], $values['show_date_modify'], $values['date_modify'], $values['seo_link'], $values['meta_title'],
$values['meta_description'], $values['meta_keywords'], $values['layout_id'], $values['pages'], $values['noindex'], $values['repeat_entry'], $values['copy_from'], $values['social_icons'], $values['block_direct_access']
) )
$response = [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
/**
* @deprecated Routing kieruje do admin\Controllers\ArticlesController::edit().
* Ta metoda pozostaje tylko jako fallback dla starej architektury.
*/
public static function article_edit() {
global $user;
if ( !$user ) {
header( 'Location: /admin/' );
exit;
}
\admin\factory\Articles::delete_nonassigned_images();
\admin\factory\Articles::delete_nonassigned_files();
return \Tpl::view( 'articles/article-edit', [
'article' => \admin\factory\Articles::article_details( (int)\S::get( 'id' ) ),
'menus' => \admin\factory\Pages::menus_list(),
'languages' => \admin\factory\Languages::languages_list(),
'layouts' => \admin\factory\Layouts::layouts_list(),
'user' => $user
] );
}
/**
* @deprecated Routing kieruje do admin\Controllers\ArticlesController::list().
* Ta metoda pozostaje tylko jako fallback dla starej architektury.
*/
public static function view_list()
{
return \admin\view\Articles::articles_list();
}
}
?>

View File

@@ -2,23 +2,14 @@
namespace admin\factory;
class Articles
{
/**
* @deprecated Logika przeniesiona do Domain\Article\ArticleRepository::saveGalleryOrder().
*/
public static function gallery_order_save( $article_id, $order )
{
global $mdb;
$order = explode( ';', $order );
if ( is_array( $order ) and !empty( $order ) ) foreach ( $order as $image_id )
{
$mdb -> update( 'pp_articles_images', [
'o' => $i++
], [
'AND' => [
'article_id' => $article_id,
'id' => $image_id
]
] );
}
return true;
$repository = new \Domain\Article\ArticleRepository( $mdb );
return $repository->saveGalleryOrder( (int)$article_id, (string)$order );
}
public static function image_alt_change( $image_id, $image_alt )

View File

@@ -3,12 +3,6 @@ namespace admin\view;
class Articles
{
public static function browse_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'articles/articles-browse-list' );
}
public static function subpages_list( $pages, $article_pages, $parent_id = 0, $step = 1 )
{
$tpl = new \Tpl();
@@ -25,4 +19,4 @@ class Articles
return $tpl -> render( 'articles/articles-list' );
}
}
?>
?>

View File

@@ -874,6 +874,10 @@ class S
$htaccess_data .= 'RewriteCond %{REQUEST_FILENAME} !-d' . PHP_EOL;
$htaccess_data .= 'RewriteRule ^ index.php [L]';
// Niektore hostingi blokuja zmiane wersji PHP przez .htaccess.
// Automatycznie komentujemy niedozwolone dyrektywy, aby generowany plik byl kompatybilny.
$htaccess_data = preg_replace( '/^(\\s*)(AddHandler|SetHandler|ForceType)\\b/im', '$1# $2', $htaccess_data );
$fp = fopen( $dir . '.htaccess', 'w' );
fwrite( $fp, $htaccess_data );
fclose( $fp );

View File

@@ -1,6 +1,6 @@
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-lsphp83 /opt/alt/php83 usr/bin/lsphp
</FilesMatch>
# <FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
# SetHandler application/x-lsphp83 /opt/alt/php83 usr/bin/lsphp
# </FilesMatch>
RewriteEngine On
RewriteBase /
@@ -25,7 +25,7 @@ ErrorDocument 404 /index.php
RewriteCond %{REQUEST_URI} !^(.*)/libraries/(.*) [NC]
RewriteCond %{REQUEST_URI} !^(.*)/layout/(.*) [NC]
RewriteRule ^admin/([^/]*)/([^/]*)/(.*)$ admin/index.php?module=$1&action=$2&$3 [L]
RewriteRule ^admin/([^/]*)/([^/]*)/(.*)$ admin/index.php?module=$1&action=$2&$3 [QSA,L]
RewriteRule ^admin/$ admin/index.php [L]
@@ -86,4 +86,4 @@ RewriteRule ^ /%1 [R=301,L]
<Files *.ini>
Order Deny,Allow
Deny from all
</Files>
</Files>

47
test.ps1 Normal file
View File

@@ -0,0 +1,47 @@
Param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$PhpUnitArgs
)
$ErrorActionPreference = "Stop"
function Resolve-PhpExe {
$cmd = Get-Command php -ErrorAction SilentlyContinue
if ($cmd -and $cmd.Source) {
return $cmd.Source
}
$candidates = @(
"C:\xampp\php\php.exe",
"C:\php\php.exe",
"C:\Program Files\PHP\php.exe"
)
foreach ($candidate in $candidates) {
if (Test-Path $candidate) {
return $candidate
}
}
throw "Nie znaleziono interpretera PHP. Dodaj php do PATH albo zainstaluj PHP (np. XAMPP)."
}
$phpExe = Resolve-PhpExe
$phpUnitPhar = Join-Path $PSScriptRoot "phpunit.phar"
if (-not (Test-Path $phpUnitPhar)) {
throw "Brak pliku phpunit.phar w katalogu projektu: $PSScriptRoot"
}
$args = @($phpUnitPhar, "--do-not-cache-result") + $PhpUnitArgs
Write-Host ""
Write-Host "================================"
Write-Host " Testy jednostkowe shopPRO"
Write-Host "================================"
Write-Host "PHP: $phpExe"
Write-Host "Cmd: $phpExe $($args -join ' ')"
Write-Host ""
& $phpExe @args
exit $LASTEXITCODE

View File

@@ -363,6 +363,56 @@ class ArticleRepositoryTest extends TestCase
$this->assertNotEmpty($fileDeletes);
}
public function testSaveGalleryOrderUpdatesImageOrder(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->exactly(3))
->method('update')
->withConsecutive(
[
'pp_articles_images',
['o' => 0],
['AND' => ['article_id' => 12, 'id' => 50]]
],
[
'pp_articles_images',
['o' => 1],
['AND' => ['article_id' => 12, 'id' => 51]]
],
[
'pp_articles_images',
['o' => 2],
['AND' => ['article_id' => 12, 'id' => 52]]
]
)
->willReturn(true);
$repository = new ArticleRepository($mockDb);
$result = $repository->saveGalleryOrder(12, '50;51;52');
$this->assertTrue($result);
}
public function testSaveGalleryOrderSkipsEmptyValues(): void
{
$mockDb = $this->createMock(\medoo::class);
$mockDb->expects($this->once())
->method('update')
->with(
'pp_articles_images',
['o' => 0],
['AND' => ['article_id' => 7, 'id' => 99]]
)
->willReturn(true);
$repository = new ArticleRepository($mockDb);
$result = $repository->saveGalleryOrder(7, ';99;');
$this->assertTrue($result);
}
public function testArchiveSetsStatusToMinusOne(): void
{
$mockDb = $this->createMock(\medoo::class);
@@ -392,4 +442,95 @@ class ArticleRepositoryTest extends TestCase
$this->assertFalse($result);
}
public function testListForAdminWhitelistsSortAndDirection(): void
{
$mockDb = $this->createMock(\medoo::class);
$queries = [];
$mockDb->method('query')
->willReturnCallback(function ($sql, $params = []) use (&$queries) {
$queries[] = ['sql' => $sql, 'params' => $params];
if (strpos($sql, 'COUNT(0)') !== false) {
return new class {
public function fetchAll()
{
return [[1]];
}
};
}
return new class {
public function fetchAll()
{
return [[
'id' => 1,
'date_add' => '2020-01-01 00:00:00',
'date_modify' => '2020-01-01 00:00:00',
'status' => 1,
'title' => 'A',
'user' => 'admin',
]];
}
};
});
$repository = new ArticleRepository($mockDb);
$repository->listForAdmin(
[],
'date_add DESC; DROP TABLE pp_articles; --',
'DESC; DELETE FROM pp_users; --',
1,
100000
);
$this->assertCount(2, $queries);
$dataSql = $queries[1]['sql'];
$this->assertMatchesRegularExpression('/ORDER BY\s+pa\.date_add\s+DESC,\s+pa\.id\s+DESC/i', $dataSql);
$this->assertStringNotContainsString('DROP TABLE', $dataSql);
$this->assertStringNotContainsString('DELETE FROM pp_users', $dataSql);
$this->assertMatchesRegularExpression('/LIMIT\s+100\s+OFFSET\s+0/i', $dataSql);
}
public function testListForAdminUsesBoundParamsForTitleFilter(): void
{
$mockDb = $this->createMock(\medoo::class);
$queries = [];
$attack = "' OR 1=1 --";
$mockDb->method('query')
->willReturnCallback(function ($sql, $params = []) use (&$queries) {
$queries[] = ['sql' => $sql, 'params' => $params];
if (strpos($sql, 'COUNT(0)') !== false) {
return new class {
public function fetchAll()
{
return [[0]];
}
};
}
return new class {
public function fetchAll()
{
return [];
}
};
});
$repository = new ArticleRepository($mockDb);
$repository->listForAdmin(['title' => $attack], 'title', 'ASC', 1, 15);
$this->assertCount(2, $queries);
$countSql = $queries[0]['sql'];
$countParams = $queries[0]['params'];
$this->assertStringContainsString('LIKE :title', $countSql);
$this->assertStringNotContainsString($attack, $countSql);
$this->assertArrayHasKey(':title', $countParams);
$this->assertSame('%' . $attack . '%', $countParams[':title']);
}
}

View File

@@ -37,6 +37,11 @@ class ArticlesControllerTest extends TestCase
$this->assertTrue(method_exists($this->controller, 'edit'));
}
public function testHasGalleryOrderSaveMethod(): void
{
$this->assertTrue(method_exists($this->controller, 'galleryOrderSave'));
}
public function testListMethodReturnType(): void
{
$reflection = new \ReflectionClass($this->controller);
@@ -49,6 +54,12 @@ class ArticlesControllerTest extends TestCase
$this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
}
public function testGalleryOrderSaveMethodReturnType(): void
{
$reflection = new \ReflectionClass($this->controller);
$this->assertEquals('void', (string)$reflection->getMethod('galleryOrderSave')->getReturnType());
}
public function testConstructorRequiresArticleRepository(): void
{
$reflection = new \ReflectionClass(ArticlesController::class);

BIN
updates/0.20/ver_0.245.zip Normal file

Binary file not shown.

View File

@@ -0,0 +1,2 @@
F: ../autoload/admin/controls/class.Articles.php
F: ../admin/templates/articles/articles-browse-list.php

View File

@@ -1,4 +1,11 @@
<b>ver. 0.244</b><br />
<b>ver. 0.245</b><br />
- UPDATE - refaktoryzacja listy artykulow: wspolny komponent `admin/templates/components/table-list.php` + `PaginatedTableViewModel`
- NEW - `admin\Support\TableListRequestFactory` (wspolna obsluga filtrow, sortowania i paginacji dla list)
- UPDATE - `Domain\Article\ArticleRepository::listForAdmin()` utwardzone pod katem bezpieczenstwa (whitelist sortowania, bind params, limit per_page)
- UPDATE - usunieto legacy `browse_list` dla modulu Articles
- UPDATE - usuniete pliki legacy sa wyszczegolnione w `updates/0.20/ver_0.245_files.txt`
- FIX - generator `.htaccess` i `libraries/htaccess.conf` (QSA dla `/admin/...`, komentarz niedozwolonych dyrektyw `SetHandler/AddHandler/ForceType`)
<hr><b>ver. 0.244</b><br />
- UPDATE - refaktoryzacja: article_save przeniesiony do Domain\Article\ArticleRepository::save() z prywatnymi helperami
- UPDATE - refaktoryzacja: article_delete przeniesiony do Domain\Article\ArticleRepository::archive()
- UPDATE - ArticlesController: nowe akcje save() i delete() z DI
@@ -313,3 +320,4 @@

View File

@@ -1,5 +1,5 @@
<?
$current_ver = 244;
$current_ver = 245;
for ($i = 1; $i <= $current_ver; $i++)
{