Skip to content

Commit

Permalink
Redraft of webservices
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Jan 1, 2019
1 parent 5c0b3e7 commit e3a131f
Show file tree
Hide file tree
Showing 48 changed files with 3,084 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .drone.yml
Expand Up @@ -81,6 +81,11 @@ pipeline:
commands:
- bash libraries/vendor/joomla/test-system/src/drone-run.sh "$(pwd)"

api-tests:
image: joomlaprojects/docker-systemtests:latest
commands:
- bash libraries/vendor/joomla/test-api/drone-run.sh "$(pwd)"

analysis3x:
image: rips/rips-cli
secrets: [rips_username, rips_password]
Expand Down
14 changes: 13 additions & 1 deletion administrator/components/com_content/Model/ArticlesModel.php
Expand Up @@ -199,7 +199,7 @@ protected function getListQuery()
'list.select',
'DISTINCT a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' .
', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.modified, a.ordering, a.featured, a.language, a.hits' .
', a.publish_up, a.publish_down'
', a.publish_up, a.publish_down, a.introtext'
)
);
$query->from('#__content AS a');
Expand Down Expand Up @@ -600,6 +600,18 @@ public function getItems()
}
}

$asset = new \Joomla\CMS\Table\Asset($this->getDbo());

foreach (array_keys($items) as $x)
{
$items[$x]->typeAlias = 'com_content.article';

$asset->loadByName('com_content.article.' . $items[$x]->id);

// Re-inject the asset id.
$items[$x]->asset_id = $asset->id;
}

return $items;
}
}
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_API-AUTHENTICATION_BASIC="API Authentication - Basic Auth"
PLG_AUTH_AUTHENTICATION_BASIC_XML_DESCRIPTION="Used to allow basic authentication to webservices in Joomla."
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_API-AUTHENTICATION_BASIC="API Authentication - Basic Auth"
PLG_AUTH_AUTHENTICATION_BASIC_XML_DESCRIPTION="Used to allow basic authentication to webservices in Joomla."
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_WEBSERVICES_CONTENT="Webservices - Content"
PLG_WEBSERVICES_CONTENT_XML_DESCRIPTION="Used to add articles routes to the API for your website."
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2017 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_WEBSERVICES_CONTENT="Webservices - Content"
PLG_WEBSERVICES_CONTENT_XML_DESCRIPTION="Used to add articles routes to the API for your website."
30 changes: 30 additions & 0 deletions api/components/com_content/Controller/ArticleController.php
@@ -0,0 +1,30 @@
<?php
/**
* @package Joomla.API
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Content\Api\Controller;

defined('_JEXEC') or die;

use Joomla\CMS\MVC\Controller\ApiController;

/**
* The article controller
*
* @since __DEPLOY_VERSION__
*/
class ArticleController extends ApiController
{
/**
* The content type of the item.
*
* @var string
* @since __DEPLOY_VERSION__
*/
protected $contentType = 'articles';
}
29 changes: 29 additions & 0 deletions api/components/com_content/View/Articles/JsonapiView.php
@@ -0,0 +1,29 @@
<?php
/**
* @package Joomla.API
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Content\Api\View\Articles;

defined('_JEXEC') or die;

use Joomla\CMS\MVC\View\JsonApiView as BaseApiView;

/**
* The article controller
*
* @since __DEPLOY_VERSION__
*/
class JsonapiView extends BaseApiView
{
/**
* The fields to render in the documents
*
* @var string
*/
protected $fieldsToRender = ['id', 'typeAlias', 'asset_id', 'title', 'introtext', 'state', 'catid', 'created'];
}
54 changes: 54 additions & 0 deletions api/includes/app.php
@@ -0,0 +1,54 @@
<?php
/**
* @package Joomla.API
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

// Saves the start time and memory usage.
$startTime = microtime(1);
$startMem = memory_get_usage();

if (file_exists(dirname(__DIR__) . '/defines.php'))
{
include_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}

require_once JPATH_BASE . '/includes/framework.php';

// Set profiler start time and memory usage and mark afterLoad in the profiler.
JDEBUG ? JProfiler::getInstance('Application')->setStart($startTime, $startMem)->mark('afterLoad') : null;

// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();

/*
* Alias the session service keys to the web session service as that is the primary session backend for this application
*
* In addition to aliasing "common" service keys, we also create aliases for the PHP classes to ensure autowiring objects
* is supported. This includes aliases for aliased class names, and the keys for alised class names should be considered
* deprecated to be removed when the class name alias is removed as well.
*/
$container->alias('session', 'session.cli')
->alias('JSession', 'session.cli')
->alias(\Joomla\CMS\Session\Session::class, 'session.cli')
->alias(\Joomla\Session\Session::class, 'session.cli')
->alias(\Joomla\Session\SessionInterface::class, 'session.cli');

// Instantiate the application.
$app = $container->get(\Joomla\CMS\Application\ApiApplication::class);

// Set the application as global app
\Joomla\CMS\Factory::$application = $app;

// Execute the application.
$app->execute();
26 changes: 26 additions & 0 deletions api/includes/defines.php
@@ -0,0 +1,26 @@
<?php
/**
* @package Joomla.API
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

// Global definitions
$parts = explode(DIRECTORY_SEPARATOR, JPATH_BASE);
array_pop($parts);

// Defines.
define('JPATH_ROOT', implode(DIRECTORY_SEPARATOR, $parts));
define('JPATH_SITE', JPATH_ROOT);
define('JPATH_CONFIGURATION', JPATH_ROOT);
define('JPATH_ADMINISTRATOR', JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator');
define('JPATH_LIBRARIES', JPATH_ROOT . DIRECTORY_SEPARATOR . 'libraries');
define('JPATH_PLUGINS', JPATH_ROOT . DIRECTORY_SEPARATOR . 'plugins');
define('JPATH_INSTALLATION', JPATH_ROOT . DIRECTORY_SEPARATOR . 'installation');
define('JPATH_THEMES', JPATH_BASE . DIRECTORY_SEPARATOR . 'templates');
define('JPATH_CACHE', JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'cache');
define('JPATH_MANIFESTS', JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'manifests');
define('JPATH_API', JPATH_ROOT . DIRECTORY_SEPARATOR . 'api');
88 changes: 88 additions & 0 deletions api/includes/framework.php
@@ -0,0 +1,88 @@
<?php
/**
* @package Joomla.API
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

// System includes
require_once JPATH_LIBRARIES . '/bootstrap.php';

// Installation check, and check on removal of the install directory.
if (!file_exists(JPATH_CONFIGURATION . '/configuration.php')
|| (filesize(JPATH_CONFIGURATION . '/configuration.php') < 10)
|| (file_exists(JPATH_INSTALLATION . '/index.php') && (false === (new JVersion)->isInDevelopmentState())))
{
if (file_exists(JPATH_INSTALLATION . '/index.php'))
{
header('Location: ../installation/index.php');

exit();
}
else
{
echo 'No configuration file found and no installation code available. Exiting...';

exit;
}
}

// Pre-Load configuration. Don't remove the Output Buffering due to BOM issues, see JCode 26026
ob_start();
require_once JPATH_CONFIGURATION . '/configuration.php';
ob_end_clean();

// System configuration.
$config = new JConfig;

// Set the error_reporting
switch ($config->error_reporting)
{
case 'default':
case '-1':
break;

case 'none':
case '0':
error_reporting(0);

break;

case 'simple':
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', 1);

break;

case 'maximum':
error_reporting(E_ALL);
ini_set('display_errors', 1);

break;

case 'development':
error_reporting(-1);
ini_set('display_errors', 1);

break;

default:
error_reporting($config->error_reporting);
ini_set('display_errors', 1);

break;
}

define('JDEBUG', $config->debug);

unset($config);

// System profiler
if (JDEBUG)
{
// @deprecated 4.0 - The $_PROFILER global will be removed
$_PROFILER = JProfiler::getInstance('Application');
}
36 changes: 36 additions & 0 deletions api/index.php
@@ -0,0 +1,36 @@
<?php
/**
* @package Joomla.API
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

/**
* NOTE: This file should remain compatible with PHP 5.2 to allow us to run our PHP minimum check and show a friendly error message
*/

/**
* Define the application's minimum supported PHP version as a constant so it can be referenced within the application.
*/
define('JOOMLA_MINIMUM_PHP', '7.0');

if (version_compare(PHP_VERSION, JOOMLA_MINIMUM_PHP, '<'))
{
die(
str_replace(
array('{{PHP_VERSION}}', '{{BASEPATH}}'),
array(JOOMLA_MINIMUM_PHP, 'http://' . $_SERVER['SERVER_NAME'] . '/'),
file_get_contents(dirname(__FILE__) . '/../templates/system/incompatible.html')
)
);
}

/**
* Constant that is checked in included files to prevent direct access.
* define() is used rather than "const" to not error for PHP 5.2 and lower
*/
define('_JEXEC', 1);

// Run the application - All executable code should be triggered through this file
require_once dirname(__FILE__) . '/includes/app.php';
6 changes: 5 additions & 1 deletion composer.json
Expand Up @@ -65,6 +65,7 @@
"joomla/oauth1": "~2.0@dev",
"joomla/oauth2": "~2.0@dev",
"joomla/registry": "~2.0@dev",
"joomla/router": "~2.0@dev",
"joomla/session": "~2.0@dev",
"joomla/string": "~2.0@dev",
"joomla/uri": "~2.0@dev",
Expand All @@ -86,6 +87,8 @@
"symfony/yaml": "3.4.*",
"wamania/php-stemmer": "^1.2",
"maximebf/debugbar": "^1.15",
"tobscure/json-api": "^0.4.1",
"willdurand/negotiation": "^2.3",
"ext-json": "*"
},
"require-dev": {
Expand All @@ -98,6 +101,7 @@
"joomla-projects/joomla-browser": "~4.0@dev",
"joomla-projects/robo-joomla": "dev-develop",
"joomla/test-system": "dev-4.0-dev",
"joomla/test-unit": "dev-4.0-dev"
"joomla/test-unit": "dev-4.0-dev",
"joomla/test-api": "dev-4.0-dev"
}
}

0 comments on commit e3a131f

Please sign in to comment.