Skip to content

Commit

Permalink
Small api simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Jun 24, 2020
1 parent c618929 commit 5f8c855
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
11 changes: 4 additions & 7 deletions lib/midcom/services/rcs/main.php
Expand Up @@ -39,12 +39,13 @@ public function __construct(midcom_config $config)
/**
* Factory function for the handler object.
*/
public function load_backend($object) : ?midcom_services_rcs_backend
public function load_backend($object) : midcom_services_rcs_backend
{
if (!$object->guid) {
return null;
$class = midcom_services_rcs_backend_null::class;
} else {
$class = $this->config->get_backend_class();
}
$class = $this->config->get_backend_class();
return new $class($object, $this->config);
}

Expand All @@ -60,10 +61,6 @@ public function update($object, $message = null) : bool
return true;
}
$backend = $this->load_backend($object);
if (!is_object($backend)) {
debug_add('Could not load handler!');
return false;
}
if (!$backend->update($object, $message)) {
debug_add('RCS: Could not save file!');
return false;
Expand Down
4 changes: 0 additions & 4 deletions lib/net/nemein/wiki/handler/latest.php
Expand Up @@ -36,10 +36,6 @@ private function _seek_updated(int $from, $to = null)

foreach ($qb->execute() as $page) {
$rcs_handler = $rcs->load_backend($page);
if (!$rcs_handler) {
// Skip this one
continue;
}

// Get object history
foreach ($rcs_handler->list_history() as $version => $history) {
Expand Down
6 changes: 1 addition & 5 deletions lib/net/nemein/wiki/wikipage.php
Expand Up @@ -175,11 +175,7 @@ private function update_watchers()
private function get_diff() : string
{
// Load the RCS handler
$rcs = midcom::get()->rcs;
$rcs_handler = $rcs->load_backend($this);
if (!$rcs_handler) {
return null;
}
$rcs_handler = midcom::get()->rcs->load_backend($this);

// Find out what versions to diff
$history = $rcs_handler->list_history_numeric();
Expand Down
2 changes: 1 addition & 1 deletion test/midcom/services/rcs/mainTest.php
Expand Up @@ -23,7 +23,7 @@ public function test_load_backend()
$rcs = new midcom_services_rcs($conf);
$topic = new midcom_db_topic;
$handler = $rcs->load_backend($topic);
$this->assertNull($handler);
$this->assertInstanceOf(midcom_services_rcs_backend_null::class, $handler);

$topic = $this->create_object(midcom_db_topic::class);
$handler = $rcs->load_backend($topic);
Expand Down

0 comments on commit 5f8c855

Please sign in to comment.