diff --git a/feeds.info b/feeds.info index bf3784b5113ab92bd50dc3a921738e5ea24c6a22..14a04b0ca2836063b5d78f52f81a39c3fe56f71f 100644 --- a/feeds.info +++ b/feeds.info @@ -15,6 +15,7 @@ test_dependencies[] = rules:rules test_dependencies[] = variable:variable files[] = includes/FeedsAccountSwitcher.inc +files[] = includes/FeedsAccountSwitcherException.inc files[] = includes/FeedsAccountSwitcherInterface.inc files[] = includes/FeedsConfigurable.inc files[] = includes/FeedsHTTPCache.inc diff --git a/includes/FeedsAccountSwitcher.inc b/includes/FeedsAccountSwitcher.inc index 5bc77394961b48acebc111ec3a1cfaf652507844..476e2eb84105f19437ecfd353a100c6b1392a852 100644 --- a/includes/FeedsAccountSwitcher.inc +++ b/includes/FeedsAccountSwitcher.inc @@ -78,7 +78,7 @@ class FeedsAccountSwitcher implements FeedsAccountSwitcherInterface { $this->activateCurrentUser(); } else { - throw new RuntimeException('No more accounts to revert to.'); + throw new FeedsAccountSwitcherException('No more accounts to revert to.'); } // Restore original session saving status if all account switches are // reverted. diff --git a/includes/FeedsAccountSwitcherException.inc b/includes/FeedsAccountSwitcherException.inc new file mode 100644 index 0000000000000000000000000000000000000000..fc806df248fc51d03a0c512c6308b96b60ba813c --- /dev/null +++ b/includes/FeedsAccountSwitcherException.inc @@ -0,0 +1,12 @@ +<?php + +/** + * @file + * Contains FeedsAccountSwitcherException. + */ + +/** + * Thrown when there is no account to switch back to. + */ +class FeedsAccountSwitcherException extends RuntimeException { +} diff --git a/includes/FeedsAccountSwitcherInterface.inc b/includes/FeedsAccountSwitcherInterface.inc index dd7fab3544405f2a8759aa2664336c186ad562a0..517ef220a0431a911ec7f42712a34b4be7f9a978 100644 --- a/includes/FeedsAccountSwitcherInterface.inc +++ b/includes/FeedsAccountSwitcherInterface.inc @@ -31,7 +31,7 @@ interface FeedsAccountSwitcherInterface { * @return FeedsAccountSwitcherInterface * $this. * - * @throws RuntimeException + * @throws FeedsAccountSwitcherException * When there are no more account switches to revert. */ public function switchBack(); diff --git a/includes/FeedsSource.inc b/includes/FeedsSource.inc index 307c83d8c6e53f066fb63986d7c53aba4679fedd..ad2d46f3f6c56a54db692c7bca4a62b6528abc53 100644 --- a/includes/FeedsSource.inc +++ b/includes/FeedsSource.inc @@ -933,7 +933,12 @@ class FeedsSource extends FeedsConfigurable { public function unlock() { $this->clearStates(); $this->save(); - $this->releaseLock(); + try { + $this->releaseLock(); + } + catch (FeedsAccountSwitcherException $exception) { + // Ignore switch back exceptions. + } } /** diff --git a/tests/feeds_processor_node.test b/tests/feeds_processor_node.test index 73e76aa70819fda30d31830d13e54b1c84b52e39..94c0a6378b803060fbcf9fdde10b5669c01fc128 100644 --- a/tests/feeds_processor_node.test +++ b/tests/feeds_processor_node.test @@ -650,6 +650,57 @@ class FeedsRSStoNodesTest extends FeedsWebTestCase { $this->assertEqual(0, db_query("SELECT COUNT(*) FROM {queue} WHERE name = 'feeds_source_clear'")->fetchField()); } + /** + * Tests unlocking a feed. + */ + public function testUnlock() { + // Just remove the mappings rather than creating a new importer. + $this->removeMappings('syndication', $this->getCurrentMappings('syndication')); + + $this->setPlugin('syndication', 'FeedsFileFetcher'); + $this->setPlugin('syndication', 'FeedsCSVParser'); + + $this->setSettings('syndication', NULL, array( + 'content_type' => '', + 'process_in_background' => TRUE, + 'import_period' => FEEDS_SCHEDULE_NEVER, + )); + + $this->addMappings('syndication', array( + 0 => array( + 'source' => 'title', + 'target' => 'title', + ), + 1 => array( + 'source' => 'GUID', + 'target' => 'guid', + 'unique' => TRUE, + ), + )); + + $this->importFile('syndication', $this->absolutePath() . '/tests/feeds/many_nodes_ordered.csv', 'Schedule import'); + $this->assertEqual(0, db_query("SELECT COUNT(*) FROM {node}")->fetchField()); + + // Assert that the import button is disabled. + $this->assertFieldDisabled('op'); + + // Assert that there is one import task in the queue. + $this->assertEqual(1, db_query("SELECT COUNT(*) FROM {queue} WHERE name = 'feeds_source_import'")->fetchField()); + + // Now unlock the feed. + $this->drupalPost('import/syndication/unlock', array(), 'Unlock'); + $this->assertText('Importer unlocked.'); + + // Assert that the unlock button is now disabled. + $this->drupalGet('import/syndication/unlock'); + $this->assertFieldDisabled('op'); + $this->assertText('This importer is not locked, therefore it cannot be unlocked.'); + + // And assert that the import button is no longer disabled. + $this->drupalGet('import/syndication'); + $this->assertFieldEnabled('op'); + } + /** * Tests skip new items. */