Add a dedicated Extrusion view for importing existing Joomla components and PHP libraries into JCB. Unify component-folder and SQL-dump extrusion through a single engine. Add PHP class harvesting into JCB Powers, including automatic class matching and dependency linking. Add import pairing with Create, Update, and Skip controls, dry runs, and per-record change previews. Improve SQL schema reconstruction to preserve column types, defaults, keys, indexes, and table configuration. Improve field imports to preserve XML settings, options, GUID relationships, and storage formats without double-encoding subform data. Reuse shared field definitions across views and preserve existing customizations during repeated imports. Detect unchanged records and avoid unnecessary writes during repeated Extrusion runs. Restore language strings and compiler placeholders in imported code, field XML, view markup, and SQL. Improve Site View and Custom Admin View discovery, template recovery, and Dynamic Get relationships. Fix Power namespace reconstruction to correctly preserve custom aliases and apply NamespacePrefix and ComponentNamespace placeholders. Fix duplicate Compile button submissions that could start concurrent builds and cause intermittent folder creation or deletion errors. #1318. Add Repair Existing Power Namespaces with automatic matching and namespace-only updates that preserve class code, GUIDs, and settings. Improve Power discovery performance with component-scoped matching, dependency indexes, and reusable parsing. Protect Extrusion imports against ambiguous matches, conflicting compiler paths, and stale change previews. Improve Extrusion error reporting and recovery after interrupted import requests. Improve the Extrusion interface with folder pickers, grouped filtering, bulk selection, responsive layouts, and a dedicated dashboard icon. Fix Extrusion self-compilation by preserving runtime marker literals and align import authorization with native view-access permissions. Replace execution of imported SQL with static parsing and validate source paths without executing imported PHP. Complete JSON:API generation for API-enabled Admin Views, including CRUD operations, relationships, filtering, pagination, and field-level permissions. Include generated API files in component manifests so they are installed with compiled components. Add API_ROUTES and API_ROUTES_METHOD placeholders for linked webservices plugins, supporting routes by record ID, GUID, and unique fields. Add read-only API resources for supported Site Views and Custom Admin Views using their existing Dynamic Gets. Fix API record creation when IDs and GUIDs are omitted, generate record keys on the server, and preserve existing GUIDs during updates. Fix API item and list model selection, including resource names with irregular plural forms. Fix API read permissions to support read-only users and return native JSON:API access-denied responses instead of administrator redirects. Fix cross-site scripting risks in generated views through corrected text sanitization, Joomla-native HTML escaping, and field escape settings. Fix edit-own permission bypasses by checking stored record ownership and applying field permissions to the record being saved. Strengthen file upload and deletion permissions with ownership and component permission checks. Fix subform updates that could overwrite or reassign records belonging to another parent. Block unsafe URL schemes in Markdown links and images. Use cryptographically secure randomness for generated passwords and upload names, and sanitize uploaded filenames. Fix generated IIS library access configuration and add missing index.html files to compiled folders. Complete extraction of generated-code logic from the legacy Fields, Interpretation, and Infusion helpers into dedicated compiler services. Consolidate shared compiler logic across Joomla versions while retaining version-specific generation where required. Refactor the Power parser to use PHP's native lexer for reliable handling of modern syntax, multiline declarations, and complex types. Fix JCB Search to prevent matching records from being skipped when processing successive batches. Fix compilation of database-aware Joomla 4 modules caused by a missing utility class import. Fix CLI repository resolution to report unresolved repository GUIDs without triggering a fatal error. Fix PHP warnings when the compiler's placeholder report contains no results. Fix toolbar generation when descriptions are missing or null. Preserve original source line endings when compiler processing leaves the content unchanged.
299 lines
6.9 KiB
PHP
299 lines
6.9 KiB
PHP
<?php
|
|
/**
|
|
* @package Joomla.Component.Builder
|
|
*
|
|
* @created 4th September 2022
|
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
|
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
|
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
*/
|
|
|
|
// No direct access to this JCB template file (EVER)
|
|
defined('_JCB_TEMPLATE') or die;
|
|
?>
|
|
###BOM###
|
|
namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Api\Controller;
|
|
|
|
###API_VIEW_CONTROLLER_HEADER###
|
|
|
|
// No direct access to this file
|
|
\defined('_JEXEC') or die;
|
|
|
|
/**
|
|
* ###View### Api Controller
|
|
*
|
|
* The item resource of the ###view### view: read, create, update and delete
|
|
* a record by its id or by any unique key of its table.
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
class ###View###Controller extends ApiController
|
|
{
|
|
/**
|
|
* The content type of the item.
|
|
*
|
|
* @var string
|
|
* @since 4.0.0
|
|
*/
|
|
protected $contentType = '###views###';
|
|
|
|
/**
|
|
* The default view for the display method.
|
|
*
|
|
* @var string
|
|
* @since 3.0
|
|
*/
|
|
protected $default_view = '###view###';
|
|
|
|
/**
|
|
* Method to get a model object, loading it if required.
|
|
*
|
|
* @param string $name The model name. Optional.
|
|
* @param string $prefix The class prefix. Optional.
|
|
* @param array $config Configuration array for model. Optional.
|
|
*
|
|
* @return \Joomla\CMS\MVC\Model\BaseDatabaseModel|boolean Model object on success; otherwise false on failure.
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
public function getModel($name = '', $prefix = '', $config = [])
|
|
{###API_VIEW_CONTROLLER_GETMODEL###
|
|
}
|
|
|
|
/**
|
|
* Basic display of an item view
|
|
*
|
|
* @param integer $id The primary key to display. Leave empty if you want to retrieve data from the request
|
|
*
|
|
* @return static A \JControllerLegacy object to support chaining.
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
public function displayItem($id = null)
|
|
{
|
|
if ($id === null)
|
|
{
|
|
$id = $this->getRecordId();
|
|
}
|
|
|
|
if ($id > 0 && !$this->allowView((int) $id))
|
|
{
|
|
throw new NotAllowed(Text::_('JERROR_ALERTNOAUTHOR'), 403);
|
|
}
|
|
|
|
return parent::displayItem($id);
|
|
}
|
|
|
|
/**
|
|
* Method to edit an existing record.
|
|
*
|
|
* @return static A \JControllerLegacy object to support chaining.
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
public function edit()
|
|
{
|
|
// resolve the record by its id or by any unique key of the table
|
|
$this->input->set('id', $this->getRecordId());
|
|
|
|
return parent::edit();
|
|
}
|
|
|
|
/**
|
|
* Prepare inherited PATCH values in the edit model's input representation.
|
|
*
|
|
* @param array $data Submitted values plus Joomla's raw stored-column merge.
|
|
*
|
|
* @return array
|
|
* @throws \RuntimeException When the existing record cannot be loaded.
|
|
* @since 6.2.0
|
|
*/
|
|
protected function preprocessSaveData(array $data): array
|
|
{
|
|
$data = parent::preprocessSaveData($data);
|
|
|
|
if ($this->input->getMethod() !== 'PATCH')
|
|
{
|
|
return $data;
|
|
}
|
|
|
|
$model = $this->getModel();
|
|
$table = $model->getTable();
|
|
$key = $table->getKeyName();
|
|
$id = (int) ($data[$key] ?? 0);
|
|
|
|
if ($id < 1)
|
|
{
|
|
return $data;
|
|
}
|
|
|
|
// Keep the original payload separate: null and empty values are explicit input.
|
|
$submitted = $this->input->get('data', json_decode($this->input->json->getRaw(), true), 'array');
|
|
$submitted = is_array($submitted) ? $submitted : [];
|
|
$item = $model->getItem($id);
|
|
|
|
if (!is_object($item))
|
|
{
|
|
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_RECORD_LOAD'), 500);
|
|
}
|
|
|
|
// getItem owns the inverse of each generated or expert storage transformation.
|
|
// Limit hydration to table columns; computed display properties are not input.
|
|
foreach ($table->getFields() as $field)
|
|
{
|
|
$name = $field->Field;
|
|
|
|
if ($name !== $key && !array_key_exists($name, $submitted) && property_exists($item, $name))
|
|
{
|
|
$data[$name] = $item->{$name};
|
|
}
|
|
}
|
|
|
|
// Tags are related data and therefore are absent from Joomla's table merge.
|
|
if (!array_key_exists('tags', $submitted) && isset($item->tags))
|
|
{
|
|
$tags = $item->tags;
|
|
|
|
if ($tags instanceof \Joomla\CMS\Helper\TagsHelper)
|
|
{
|
|
$data['tags'] = empty($tags->tags) ? [] : explode(',', $tags->tags);
|
|
}
|
|
elseif (is_array($tags))
|
|
{
|
|
$data['tags'] = $tags;
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Removes an item.
|
|
*
|
|
* @param integer $id The primary key to delete item.
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
public function delete($id = null)
|
|
{
|
|
if (!$this->allowDelete())
|
|
{
|
|
throw new NotAllowed(Text::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), 403);
|
|
}
|
|
|
|
if ($id === null)
|
|
{
|
|
$id = $this->getRecordId();
|
|
}
|
|
|
|
$id = (int) $id;
|
|
$model = $this->getModel();
|
|
$table = $model->getTable();
|
|
|
|
if ($id < 1 || !$table->load($id))
|
|
{
|
|
throw new ResourceNotFound(Text::_('JLIB_APPLICATION_ERROR_RECORD'), 404);
|
|
}
|
|
|
|
$pks = [$id];
|
|
|
|
if (!$model->delete($pks))
|
|
{
|
|
$session = $this->app->getSession();
|
|
|
|
if ($session->get('http_status_code_404', false))
|
|
{
|
|
$session->clear('http_status_code_404');
|
|
|
|
throw new ResourceNotFound(Text::_('JLIB_APPLICATION_ERROR_RECORD'), 404);
|
|
}
|
|
|
|
if ($session->get('http_status_code_409', false))
|
|
{
|
|
$session->clear('http_status_code_409');
|
|
|
|
throw new \RuntimeException('Resource not in state that can be deleted, must be trashed before it can be deleted', 409);
|
|
}
|
|
|
|
$error = $model->getError();
|
|
|
|
if ($error)
|
|
{
|
|
throw new \RuntimeException($error, 500);
|
|
}
|
|
|
|
throw new NotAllowed(Text::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), 403);
|
|
}
|
|
|
|
$this->app->setHeader('status', 204);
|
|
}
|
|
|
|
/**
|
|
* Get the id of the record the request targets.
|
|
*
|
|
* The primary key is taken when the request carries it, else the record
|
|
* is resolved through the first unique key of the table the request carries.
|
|
*
|
|
* @return integer The record id, or 0 when no record matches.
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
protected function getRecordId(): int
|
|
{###API_VIEW_CONTROLLER_RECORDID###
|
|
}
|
|
|
|
/**
|
|
* Method to check if you can view a record.
|
|
*
|
|
* @param integer $id The record id.
|
|
*
|
|
* @return boolean
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
protected function allowView(int $id): bool
|
|
{###API_VIEW_CONTROLLER_ALLOWVIEW###
|
|
}
|
|
|
|
/**
|
|
* Method override to check if you can add a new record.
|
|
*
|
|
* @param array $data An array of input data.
|
|
*
|
|
* @return boolean
|
|
*
|
|
* @since 1.6
|
|
*/
|
|
protected function allowAdd($data = [])
|
|
{###JCONTROLLERFORM_ALLOWADD###
|
|
}
|
|
|
|
/**
|
|
* Method override to check if you can edit an existing record.
|
|
*
|
|
* @param array $data An array of input data.
|
|
* @param string $key The name of the key for the primary key.
|
|
*
|
|
* @return boolean
|
|
*
|
|
* @since 1.6
|
|
*/
|
|
protected function allowEdit($data = [], $key = 'id')
|
|
{###JCONTROLLERFORM_ALLOWEDIT###
|
|
}
|
|
|
|
/**
|
|
* Method to check if it's allowed to delete a record.
|
|
*
|
|
* @return boolean
|
|
*
|
|
* @since 4.0.0
|
|
*/
|
|
protected function allowDelete(): bool
|
|
{###API_VIEW_CONTROLLER_ALLOWDELETE###
|
|
}
|
|
}
|