/** * Preforms Batch action against all Webservices * * @param string $action Action to preform * * @return boolean Returns true if Action was successful */ public function batchWebservices($action = '') { $webservices = RApiHalHelper::getWebservices(); if (!empty($webservices)) { $model = $this->getModel('webservices'); $installedWebservices = RApiHalHelper::getInstalledWebservices(); foreach ($webservices as $webserviceNames) { foreach ($webserviceNames as $webserviceVersions) { foreach ($webserviceVersions as $webservice) { $client = RApiHalHelper::getWebserviceClient($webservice); $path = $webservice->webservicePath; $name = (string) $webservice->config->name; $version = (string) $webservice->config->version; // If it is already install then we skip it if (!empty($installedWebservices[$client][$name][$version])) { continue; } switch ($action) { case 'install': $model->installWebservice($client, $name, $version, $path); break; case 'delete': $model->deleteWebservice($client, $name, $version, $path); break; } } } } } return true; }
<?php foreach ($this->xmlFiles as $clients => $webserviceNames) { ?> <?php $column = 0; ?> <div class='clearfix'></div> <h3><?php echo JText::_('J' . $clients); ?> </h3> <?php foreach ($webserviceNames as $webserviceVersions) { foreach ($webserviceVersions as $webservice) { $webserviceClient = RApiHalHelper::getWebserviceClient($webservice); ?> <div class="col-md-4 well"> <h4> <?php echo $webservice->name; ?> (<?php echo $webservice->config->name; ?> <?php echo !empty($webservice->config->version) ? $webservice->config->version : ''; ?> ) </h4>
/** * Install Webservice from site * * @param string $client Client * @param string $webservice Webservice Name * @param string $version Webservice version * @param string $path Path to webservice files * @param int $id Path to webservice files * * @return boolean Returns id if Webservice was successfully installed */ public function installWebservice($client = '', $webservice = '', $version = '1.0.0', $path = '', $id = 0) { $webserviceXml = RApiHalHelper::getWebservices($client, $webservice, $version, $path, true); if (!empty($webserviceXml)) { $operations = array(); $scopes = array(); $client = RApiHalHelper::getWebserviceClient($webserviceXml); $version = !empty($webserviceXml->config->version) ? (string) $webserviceXml->config->version : $version; if (!empty($webserviceXml->operations)) { foreach ($webserviceXml->operations as $operation) { foreach ($operation as $key => $method) { if ($key == 'task') { foreach ($method as $taskKey => $task) { $displayName = !empty($task['displayName']) ? (string) $task['displayName'] : $key . ' ' . $taskKey; $scopes[] = array('scope' => strtolower($client . '.' . $webservice . '.' . $key . '.' . $taskKey), 'scopeDisplayName' => ucfirst($displayName)); } } else { $operations[] = strtoupper(str_replace(array('read', 'create', 'update'), array('GET', 'PUT', 'POST'), $key)); $displayName = !empty($method['displayName']) ? (string) $method['displayName'] : $key; $scopes[] = array('scope' => strtolower($client . '.' . $webservice . '.' . $key), 'scopeDisplayName' => ucfirst($displayName)); } } } } RApiHalHelper::$installedWebservices[$client][$webservice][$version] = array('name' => $webservice, 'version' => $version, 'title' => (string) $webserviceXml->name, 'path' => (string) $path, 'xmlFile' => $client . '.' . $webservice . '.' . $version . '.xml', 'xmlHashed' => md5($webserviceXml), 'operations' => json_encode($operations), 'scopes' => json_encode($scopes), 'client' => $client, 'state' => 1, 'id' => $id); /** @var RedcoreTableWebservice $table */ $table = RTable::getInstance('Webservice', 'RedcoreTable'); $table->bind(RApiHalHelper::$installedWebservices[$client][$webservice][$version]); // Check the data. if (!$table->check()) { return false; } if (!$table->store()) { if (empty($id)) { $this->setError(JText::sprintf('COM_REDCORE_WEBSERVICES_WEBSERVICE_NOT_INSTALLED', $table->getError())); } return false; } RApiHalHelper::saveOAuth2Scopes($client, $webservice, $scopes, false); $this->setState($this->getName() . '.id', $table->id); return $table->id; } return false; }