Repository navigation
4.1.1.32
Changes
- New ControllerAdminList (optional, like ControllerAdminForm for forms): the admin list with the defaults $use_default_list = true and $enable_delete = true; delete() and deleteRecord() need the 'modify' permission of PAGE_ROUTE (validateDelete()). ControllerList is not changed (no permission check, it is generic). Field metadata 'options' (ADBTable): value => text, shown as the text of the value in the default list (formatListValue()), used by 'select' filters and select form fields; options from the database: the name of a method of the table class or a closure, resolved when needed by the new ADBTable::getOptions($code) (kept per object); new helpers ADBTable::getStoreOptions() (store_id => name, the default store first) and getLanguageOptions() (language_id => name), e.g. 'store_id' => ['type' => 'select', 'options' => 'getStoreOptions', 'list' => true]. Arrays in 'options' work as before. New admin language string column_action ('Action', ru-ru), the column of the default list table. Simple read queries of the library are built with QB: Language (by id, by code), Store (store, its settings), Format (weight / length units; the class id is cast to int now). Tests: unit TableMetaTest, ControllersTest, integration DefaultListTest (groups lists, forms).
- QB hooks: new trait TraitQB with getQB($table = '', $alias = '') and onQB($table, $callback, $sort_order = 0) (returns a subscription id), offQB($id) (removes it, an unknown id is ignored), used by the base Model and Controller of the library; a developer can use it in other classes too, e.g. a kamod child of a standard OpenCart model: class ModelCatalogProduct extends \ModelCatalogProduct { use \extension\ka_extensions\TraitQB; }. getQB() returns 'new QB()' with from($table, $alias) when the table is given and the callbacks of onQB() for the table and '' (all), use it instead of 'new QB()' so other modules can extend the queries: they subscribe with onQB() in a kamod child of the class (constructor or onLoad()) or override getQB(). The callbacks are kept by the object (protected $qb_hooks, no static storage), the ones of the table first, then '', by sort order and subscription order. Usually a module subscribes for a while in a method of a kamod child: $id = $this->onQB('product', function($qb) { $qb->where('p.ka_hidden', 0); }); $result = parent::getRecords($filter); $this->offQB($id); getQB() copies the current callbacks into the QB object, so a QB made while the subscription was active keeps the callback after offQB(), QB objects made after offQB() do not get it. QB: the table key is the table of the first from() call (QB::getTable(), joins do not change it, queries of several tables in from() are not supported by the hooks), QB::addHook($callback) - a callback called with the QB object at the start of every getSql() call (also query(), ModelRecordset::getRecordsTotal(), the QB objects inside fromUnionAll() run their own hooks once per getSql() of the outer one), so it may run several times per object. 'new QB()' works as before. Docs: docgen/guides/code_design_guidlines.rst. Tests: unit QBHooksTest, integration QbHooksTest (group smoke).
- JavaScript: the class KaExtensions is moved from common.js to its own file kaextensions.js (admin: admin/view/javascript/extension/ka_extensions/, storefront: catalog/view/javascript/extension/ka_extensions/) together with $.ka.alert() and the admin click handler of data-ka-post / legacy delete links (registered when the object is created, delegated to the document). The library header adds kaextensions.js and creates the object ka_extensions right after it in the head of the page (an inline script in the library part of the admin and storefront header.twig), so inline code of the page can use it. common.js is removed (admin and storefront): third-party code including extension/ka_extensions/common.js has to include kaextensions.js instead (the object is created by the header). For storefront themes with their own header.twig (without the library part) the footer creates the object when it is missing. ka_extensions.getLabel(key, params): optional substitutions as in the PHP Language::getka($key, $params) (str_replace: every key of params is replaced with its value, all occurrences, in the order of the keys), e.g. getLabel('txt_deleted', {'%count%': 5}).
- Labels of the library JS: the admin and storefront footers passed the standard labels (txt_info, txt_success, txt_warning, txt_error, txt_field_validation_error) only without KA_DISABLE_FORM_VALIDATION, and the global ka_js_labels printed by footer.twig (HTML-escaped values inside a JS string: a quote was shown as ", a backslash or a line break broke the script) was read only by the form validation; the titles of ka_extensions.showMessage() were always English. Now the footers always pass the standard labels and the new txt_confirm ('Are you sure?', en-gb, ru-ru; ru-ru got all six labels), the constant turns off the form validation only. The footer prints the labels of the document (Document::addKaJsLabels()) as ka_extensions.setLabels({...}) (JSON with JSON_HEX_TAG / AMP / APOS / QUOT, safe in an inline script); no global ka_js_labels is created any more. New ka_extensions.setLabels(labels) (Object.assign into ka_extensions.labels, later calls override earlier values, modules can call it) and ka_extensions.getLabel(key) (the label, the English default, the key itself). Document::addKaJsLables() is renamed to addKaJsLabels() (the typo, no alias): modules calling the old name have to be changed. Tests: unit JsLabelsTest, integration JsLabelsTest (group smoke), tests/e2e/common_js_post_links.js.
- Build (ka_build.php 3.3.3.0, the copy in this repository; synced with ka_tools/ka_build.o2 r275 first): the header keywords
$Project$ ,$Author$ ,$Version$ ,$Revision$ were not filled in the packages built from git (git has no keyword expansion, the files had the bare keywords since the move to git). The builder writes them into the package copies of the packed files, the source files are not changed: $Project: <keywords_project> $ (default: manifest 'name'), $Author: <keywords_author> $ (default: karapuz team support@ka-station.com),$Version: $ ,$Revision: $ ; the revision is the number of commits of HEAD for git (git rev-list --count HEAD), the working copy revision for svn. git: stale values (copied from svn) are written again; svn: only bare keywords, the values expanded by svn are kept. Text files only (php, tpl, twig, js, css, xml, txt, ini, html, json, md, ...), not vendor/ and node_modules/ folders, only these four names; manifest 'expand_keywords = "N"' turns it off. Test: unit BuildKeywordsTest (group build). - Default list page (optional): a list page without a template of its own (the model of the page is required, it can be an empty ModelRecordset child with $table_class). ADBTable fields can declare metadata for the list and the form, all keys optional: 'list', 'sort', 'filter' (like, eq, select, date_range), 'form' => false, 'title', 'format' (price, date, datetime, enabled), 'width', 'link' => 'edit', and the form keys 'type', 'required', 'max_length', 'options', 'default_value'; getters getListFields(), getSortFields(), getFilterFields(), getFormFields(), hasFieldMeta() (without metadata: columns and sorting by all fields except the primary key, no filters, form fields of type text). ControllerList: $use_default_list = true shows @ka_common/pages/list.twig (filter panel and table from the metadata, sort links, checkboxes with the bulk delete by POST selected[], row edit and button_row_delete(), pagination, the Add button); DEFAULT_LIST_TEMPLATE is the template of the page, a module sets its own template extending '@ka_common/pages/list.twig' to replace a part of it (blocks list_filter, list_table); getListColumns(); the filters of the metadata go to the url parameters and to getPageFilterFields() when a child class passes none; getSortFields() comes from the 'sort' metadata when a field declares it. ModelRecordset: getTable(); getRecordsQB() applies the filters of the metadata (filter_, filter__from / _to, LIKE wildcards escaped); getSortWhitelist() is built from the 'sort' metadata. ControllerForm: when getFields() returns nothing the fields come from ADBTable::getFormFields() of the recordset (set it before parent::onLoad()). Tables and pages without the metadata work as before. New language strings txt_filter_from, txt_filter_to, txt_clear_filter (en-gb, ru-ru). Tests: unit TableMetaTest, integration DefaultListTest (groups lists, forms).
- ControllerList::getPageFilterFields(): a filter value '0' from the url (e.g. store 0, status 'Disabled') was not shown in the filter field (!empty() check), the filtering itself worked. Fixed: a value is any string that is not empty (isset + strlen, not trimmed), an array is a value when it is not empty. Tests: unit ControllersTest (group lists).
- Select fields (@ka_common/fields/select.value.twig, admin and catalog): the selected option was found by the loose Twig comparison '==': with an empty value the option with key 0 was selected too (PHP 7.4 '' == 0, and null == 0 on all versions), e.g. 'Default store' or 'Disabled' in an empty filter. Fixed: the value and the key are compared as strings. Note: the radio and checkboxes fields have the same loose comparison, not changed yet. Tests: integration PagesTest (group lists).
- ControllerList: the 'delete' action of a row (fillRecord()) opens PAGE_ROUTE/deleteRecord, which accepts POST only since 4.1.1.29, so a plain link of a list template deleted nothing ('permission' error). New: the macro button_row_delete(href) of @ka_common/macros/table.twig and a handler in the admin common.js: a link with data-ka-post is posted as a hidden form after the data-confirm question. The action has the key 'method' => 'post'. Legacy row delete links of list templates are posted too: a.btn-danger with '/deleteRecord' in the href and without onclick and data-ka-post, after the question 'Are you sure?' (ka_extensions.labels.txt_confirm); so old module templates with plain delete links work with the POST-only deleteRecord() again. Other links open as before. Tests: unit ControllersTest, integration PagesTest (group lists), tests/e2e/common_js_post_links.js (Playwright).
- ControllerList: the sorted column was not highlighted by the macro sort_url(): the template got no 'sort' value or the SQL value from the url ('t.name') instead of the column code. Now index() sets 'sort' (the code of getSortFields() for the current sort, the url value when it is not there) and 'order' unless a child class set them; the macro also accepts a value with a table alias ('t.name' for 'name'). Tests: unit ControllersTest, integration PagesTest (group lists).
- ControllerList / ControllerForm: new hook getLanguageRoutes(), the language files of the page (PAGE_ROUTE for a list, PARENT_ROUTE for a form, as before), e.g. a module adds its common language file. ControllerForm: a form of a missing (deleted) record showed an empty form and its saving could report success; now the user gets the error 'error_record_not_found' (en-gb, ru-ru) and the list page, the check can be overridden (isRecordFound()). Tests: unit ControllersTest, integration PagesTest (group forms).
- TraitControllerForm::getFieldWithData(): a 'price' value 0 was not formatted (!empty() check). Fixed: strlen((string)value).
- Installed version of a module (Extensions > Ka Extensions): modules without $ext_code whose onLoad() does not call parent::onLoad() (on ka-station: Hidden Products, CSV Product Import / Export, CSV Category Export, Advanced Search, Ka Tags and others) had the module code '' and shared one hidden value '_hidden_version' (setting group '_hidden'): the page showed the version of the module installed or refreshed last as the installed version of all of them ('Files: 5.0.3.7, installed: 1.0.3.0'), the Refresh button of such a module upgraded it from that version and overwrote the value of the others (since 4.1.1.29). The code and the vendor are taken from the file name of the module in the ControllerInstaller constructor now, before onLoad(). Note: such modules have no own stored version after the update (0.0.0.0, see the next entry); the wrong row can be removed: DELETE FROM oc_setting WHERE code = '_hidden'. Test: integration InstallerExtCodeTest (group upgrade).
- Extensions > Ka Extensions: a module without a stored installed version (0.0.0.0, installed by an older library) showed the yellow Refresh button with the hint 'installed: 0.0.0.0' in its tooltip. The installed version is not known, so nothing is shown now: no button, no hint. A module with an older stored version than its files shows the button and the orange 'Files: ..., installed: ...' text as before; a request to the upgrade (POST) still works for such a module. Tests: integration UpgradeTest.
- Storefront templates changed by OCMOD modifications (system/storage/modification/catalog/view/theme) were found only for the template whose code is passed to Template\Twig::render(). Templates included by other templates ({% include %}) and all templates rendered with a re-used Twig environment (ka_speedup keeps the environment of the first template of the request) were read from the theme folder without the modification (seen on ka-station with ka_speedup: the price range of Advanced Filter in the Filter module, the Invoice Page buttons on checkout/success and account/order_info, the Multivendor parts of account/order_info and of the shipping estimator in the cart). The library twig loader had the modification folder commented out: added at its old place it would win over the copies of the theme editor (option 'Modify Theme Files' off). Fixed: the modification folder is added with the lowest priority of the library loader, the theme editor copies and the kamod cache (built over the modification files) still win, the original theme folder comes after it. Tests: integration TwigModificationTest (group kamod), ThemeFilesTest.
- PHP 8.2+: the deprecation notices 'Creation of dynamic property extension\ka_extensions\KamodBuilder::$mod_comment' (and $twig_common_cache_dir, $twig_store_cache_dir, $twig_theme_cache_dir) on every kamod cache rebuild with twig templates (seen on PHP 8.4 in the error log and in the output of the page). Fixed: the properties are declared in KamodBuilder (protected), the behaviour is not changed.
- Kamod cache: the compiled twig templates of OpenCart (system/storage/cache/template) are removed when the kamod cache is rebuilt (module installation or upgrade, Modifications > Refresh). The extension installer keeps the file times of the archive, so a template of a new module version could be older than its compiled copy and Twig (auto_reload compares file times only) kept showing the old template until the theme cache was refreshed on the dashboard (seen on OpenCart 3.0.3.8: empty vendor registration and profile pages of Multivendor 1.0.6.0). A file that cannot be removed is written to the kamod log, the rebuild goes on. Not done with KAMOD_DEBUG. Tests: integration TwigCacheTest (group kamod).
- Directory::clearDirectory(): when a subfolder could not be deleted (an exception), the nesting level was not restored and the next call in the same request deleted its root folder too (e.g. the theme cache folder after a failed clearing of the twig cache). Fixed: the level is restored in 'finally'. Test: unit DirectoryTest.
- Modify Theme Files (Extensions > Ka Extensions settings): OCMOD modifications were not shown on the storefront for templates changed in Design > Theme Editor. Modifications > Refresh built the modified file from the theme editor version, but the storefront took the theme cache copy of the template (system/storage/theme.kamod) without modifications (seen in 4.1.1.25 - 4.1.1.31). Fixed: the refresh applies the modifications to the theme cache copies of the changed templates in place (all stores, see the entry on template layering below). Saving any template in the theme editor rebuilds the theme cache, so modifications are shown again after the next Modifications > Refresh. Tests: integration ThemeFilesTest (group theme-files).
- Theme editor: a template changed in Design > Theme Editor for a theme that has no own copy of it (the template of the default theme is used) was not shown on the storefront with that theme (core OpenCart shows it). Fixed: the theme cache keeps a copy of such a change under the name the storefront requests (system/storage/theme.kamod/<store_id>/inherited//catalog/view/theme/default/template/.twig), it is used for that theme only and wins over the default template. OCMOD modifications and kapatches of the default template are applied to it, see the next entry. Note: changes of this kind saved before are shown after the update (when the theme cache is rebuilt: Modifications > Refresh or a save in the theme editor). Tests: group theme-files.
- Storefront template layering, the rules (theme T, one template): the base is the theme editor copy of theme T, otherwise the file of theme T, otherwise (T has no own file) the theme editor copy of the default theme, otherwise the file of the default theme. On top of the base OCMOD modifications are applied (to a theme editor copy only with 'Modify Theme Files' on, after Modifications > Refresh), then kapatches and kamod child templates; only the changes written for the file of the base count (the file of theme T, or the default file when T has no own file). The loader takes the kamod cache first, then the OCMOD modification file, then the original file; ka_speedup does not change the result. Changes: a theme editor copy of a theme without its own file (the previous entry) was shown as it is, without the OCMOD modifications and the kapatches / child templates of the default template. Fixed: Modifications > Refresh applies the OCMOD modifications of the default template to the copy ('Modify Theme Files' on), kamod builds the chain of the default template over the copy (system/storage/cache.kamod/templates.<store_id>/inherited//), the storefront loader of that theme takes it first. OCMOD on theme editor copies of all stores: OCMOD modifications were applied to the theme editor changes of the default store only, and the changed template of the default store was written to system/storage/modification, so other stores and themes without changes got it too (a second store showed the theme editor change of the default store). Fixed: with 'Modify Theme Files' Refresh applies the operations of every modified template to the theme editor copies of that template in all stores (system/storage/theme.kamod/<store_id>/catalog/view/theme//template/ and .../inherited/), the modification files are built from the original files as in OpenCart; the setting is global (saved for the default store). The theme editor warning 'The modifications are applied to the default store only' is removed. A kapatch in a theme folder for a template the theme does not have is skipped (it wrote an empty template to the kamod cache, kamod log 'Twig patch target was not found'). Note: such theme editor copies that already contain a change of a module made by hand get it twice after the update and Refresh; an OCMOD or kapatch search that does not match the edited copy is reported in the OCMOD / kamod logs. Tests: integration TemplateLayeringTest (the full matrix: 3 themes x 4 sets of theme editor copies x option on/off x OCMOD on/off x 4 kinds of kamod changes x before/after Refresh x ka_speedup on/off, 768 cases; the same with three stores of different themes and theme editor copies, 768 cases), ThemeFilesTest, ThemeEditorWarningTest (group theme-files).
- Theme editor: only the 10 newest changes of Design > Theme Editor (all stores together) were copied to the theme cache (system/storage/theme.kamod), the older ones were missing: they were shown without kapatches, kamod child templates and OCMOD modifications, or not shown at all. rebuildThemeCache() used the core model getThemes(), the paged list of the theme editor history (10 rows by default). Fixed: all changes of all stores are read (getThemes() with the total count as the limit); if a template has more than one row for a store and theme, the newest one is used. Note: older changes appear on the storefront after the update and Modifications > Refresh (or a save in the theme editor). Test: integration TemplateLayeringTest (15 changes in three stores, the oldest one with OCMOD and a kapatch, a duplicate row).
- Theme editor: the warning of Ka Extensions on the Theme Editor page uses the language files of the library (en-gb, ru-ru), a stray tag removed. Test: ThemeEditorWarningTest.
- Kamod, templates: a template of a module without blocks (it replaces the whole template) was ignored when the template it overrides had its own blocks, the page showed the original template (seen on ka-station: the product page of ka_mods/market was lost after Milena 1.0.2.0 added the block product_info_extra for Multivendor 1.0.6.0). Only a template without blocks was wrapped in the parent_template block, a child template overrides parent_template, so there was nothing to override. Fixed: the base template of a chain (the original one) is always wrapped in parent_template, its own blocks become nested blocks and can be overridden as before. It is not wrapped when it has the parent_template block already or the tags extends, use, macro, import, from. A full-page template of a module can keep the blocks of the original template inside it with parent(), then the blocks of other modules are shown in any order of the modules: {% block parent_template %}...{% block product_info_extra %}{{ parent() }}{% endblock %}...{% endblock %}. See docgen/guides/twig_templates.rst. Tests: integration TwigChainTest (group kamod).
- Module upgrade (the 'Refresh' button of Extensions > Ka Extensions): kamod of the module was not activated, the upgrade did not write active.kamod (admin/controller/extension//
/). A module installed by its older version without kamod.ini got kamod files in the new version, but its child classes, kapatches and templates were not applied after the upgrade (seen with Ka Tags 2.0.0.3 -> 2.0.1.0: the old search and the old OCMOD code stayed). The call was guarded by method_exists() on the setting model, an OpenCart Proxy object, so the check was always false (4.1.1.29 - 4.1.1.31). Fixed: the upgrade activates kamod of the module as the installation does (only when the module has kamod.ini). Tests: integration UpgradeTest (group upgrade). - Kamod cache: Extensions > Modifications > Refresh could leave the kamod cache built over the old modification files. The cache is valid while its marker is not older than the modification folder, file times have a one-second resolution, so a cache built in the same second as the refresh wrote the new files stayed (e.g. built by the refresh request itself after a module upgrade marked the cache invalid; seen once with Ka Tags 2.0.1.0: the code of its removed OCMOD stayed in the admin product form until the next refresh). Fixed: the refresh marks the kamod cache invalid after the modification files are written, the next request rebuilds it. The kamod log wrote 'Cache marked valid' when the cache was marked invalid, now 'Cache marked invalid'. Tests: integration KamodRefreshTest (group kamod).
What's Changed
- Clear compiled twig templates when the kamod cache is rebuilt by @gosha-bot in #25
- Theme editor: 'Modify Theme Files' applies OCMOD to edited templates; edits of themes without their own template copy are shown; localized Theme Editor warning by @gosha-bot in #26
- Kamod: always wrap the base twig template in parent_template, so a full-page module template replaces a template with its own blocks by @gosha-bot in #27
- KamodBuilder: declare properties to fix PHP 8.2+ dynamic property deprecation notices by @gosha-bot in #28
- Kamod: activate kamod of a module on upgrade (method_exists on a Proxy was always false); Modifications > Refresh marks the kamod cache invalid (same-second stale cache) by @gosha-bot in #29
- Twig loader: OCMOD-modified storefront templates for included templates and with ka_speedup (modification folder with the lowest loader priority) by @gosha-bot in #30
- Storefront template layering rules: inherited theme editor copies get OCMOD and default kapatches/children; skip theme kapatches without a target by @gosha-bot in #31
- Installed version: own code for modules without parent::onLoad(), nothing shown for 0.0.0.0 by @gosha-bot in #32
- ControllerList / ControllerForm: filter '0', strict select, POST row delete (data-ka-post), sort highlight, language hook, record not found by @gosha-bot in #33
- Default list page: ADBTable field metadata, pages/list.twig, TABLE_CLASS (depends on #33) by @gosha-bot in #34
- ka_build.php: header keywords written into the package copies by @gosha-bot in #35
- Library JS: KaExtensions class in kaextensions.js, object created in the header, labels via setLabels() in the footer; txt_confirm; addKaJsLabels typo by @gosha-bot in #36
- getQB() / onQB() in Model and Controller, QB hooks on every getSql() by @gosha-bot in #38
- ControllerAdminList, metadata options from table methods, column_action, simple reads via QB by @gosha-bot in #37
- Version 4.1.1.32 in manifest.ini and ControllerInstaller (not released) by @gosha-bot in #39
- Release 4.1.1.32: changelog heading without '(not released)', install example 4.1.1.32 by @gosha-bot in #40
Full Changelog: v4.1.1.31...v4.1.1.32