Skip to content

Commit

Permalink
Issue ThinkUpLLC#189: Fixed "no plugin object defined" error
Browse files Browse the repository at this point in the history
* When deactivating a plugin with active instances, those instances are automatically deactivated and the cache gets cleared, so those instances don't show up in the switch user dropdown and no longer cause a "no plugin object defined" error

In this fix, several related issues were also resolved:

Issue ThinkUpLLC#585: Added support for plugin activate/deactivate callbacks
* Added FacebookPlugin and TwitterPlugin deactivate callbacks to deactivate related instances

Issue ThinkUpLLC#457: Changed "accounts" to "services" and updated link to plugins area
* The link now goes to the plugins list, not directly to the Twitter plugin, because it may not be activated

Miscellaneous cleanup:
* Changed default logo link to '' instead of index.php
* URLEncoded Dashboard and logo link (for facebook page)
* Code style corrections
* Added tests

Closes ThinkUpLLC#457, closes ThinkUpLLC#585, closes ThinkUpLLC#189, closes ThinkUpLLC#673
  • Loading branch information
ginatrapani committed Mar 20, 2011
1 parent e24f26a commit 62c48f0
Show file tree
Hide file tree
Showing 27 changed files with 222 additions and 56 deletions.
4 changes: 2 additions & 2 deletions tests/TestOfDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function testNoInstancesLoggedIn() {
$results = $controller->go();

$v_mgr = $controller->getViewManager();
$this->assertPattern("/You have no accounts configured./", $v_mgr->getTemplateDataItem('infomsg'));
$this->assertPattern("/Set up an account now/", $v_mgr->getTemplateDataItem('infomsg'));
$this->assertPattern("/You have no services configured./", $v_mgr->getTemplateDataItem('infomsg'));
$this->assertPattern("/Set up a service/", $v_mgr->getTemplateDataItem('infomsg'));
}

public function testNotLoggedInNoUserOrViewSpecified() {
Expand Down
20 changes: 9 additions & 11 deletions tests/TestOfPluginHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,29 @@
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

/**
*
* Test of PluginHook class
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2011 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

class TestOfPluginHook extends ThinkUpBasicUnitTestCase {

/**
* Constructor
*/
function __construct() {
public function __construct() {
$this->UnitTestCase('PluginHook class test');
}

/**
* Test registerPlugin
*/
function testRegisterAndGetPlugin() {
public function testRegisterAndGetPlugin() {
$test_ph = new TestFauxHookableApp();
$test_ph->registerPlugin('facebook', "FacebookPlugin");
$test_ph->registerPlugin('twitter', "TwitterPlugin");
Expand All @@ -56,7 +54,7 @@ function testRegisterAndGetPlugin() {
/**
* Test getPluginObject
*/
function testGetPluginObjectDoesntExist() {
public function testGetPluginObjectDoesntExist() {
$test_ph = new TestFauxHookableApp();
$this->expectException( new Exception("No plugin object defined for: notregistered") );
$plugin_obj = $test_ph->getPluginObject("notregistered");
Expand All @@ -66,7 +64,7 @@ function testGetPluginObjectDoesntExist() {
* Test registerPerformAppFunction and emit
* @TODO Test for registering an object which does not exist; currently this causes a PHP fatal error
*/
function testRegisterPerformAppFunction() {
public function testRegisterPerformAppFunction() {
//register first, should work
$test_ph = new TestFauxHookableApp();
$test_ph->registerPerformAppFunction('TestFauxPlugin');
Expand Down
4 changes: 2 additions & 2 deletions tests/TestOfSmartyThinkUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testSmartyThinkUpAssignedValuesDebugOn() {
$this->assertEqual($smtt->getTemplateDataItem('test_var_1'), "Testing, testing, 123");

$this->assertEqual($smtt->getTemplateDataItem('app_title'), 'Testy ThinkUp Custom Application Name');
$this->assertEqual($smtt->getTemplateDataItem('logo_link'), 'index.php');
$this->assertEqual($smtt->getTemplateDataItem('logo_link'), '');
$this->assertEqual($smtt->getTemplateDataItem('site_root_path'), '/my/thinkup/folder/');
}

Expand Down Expand Up @@ -107,7 +107,7 @@ public function testSmartyThinkUpPassedInArray() {
$smtt = new SmartyThinkUp($cfg_array);

$this->assertEqual($smtt->getTemplateDataItem('app_title'), 'My ThinkUp');
$this->assertEqual($smtt->getTemplateDataItem('logo_link'), 'index.php');
$this->assertEqual($smtt->getTemplateDataItem('logo_link'), '');
$this->assertEqual($smtt->getTemplateDataItem('site_root_path'), '/my/thinkup/folder/test');
}
}
14 changes: 7 additions & 7 deletions tests/TestOfTestAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

/**
*
* Test TestAdminController class
*
* TestController isn't a real ThinkUp controller, this is just a template for all Controller tests.
*
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2011 Gina Trapani, Mark Wilkie
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

class TestOfTestAdminController extends ThinkUpUnitTestCase {
/**
* Constructor
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testLoggedInAsAdmin() {
$this->assertEqual($v_mgr->getTemplateDataItem('app_title'), 'ThinkUp');

$this->assertEqual($results,
'<a href="/my/path/to/thinkup/index.php">ThinkUp</a>: Testing, testing, 123 | Logged in as me@example.com',
'<a href="/my/path/to/thinkup/">ThinkUp</a>: Testing, testing, 123 | Logged in as me@example.com',
"auth controller output when logged in");
}

Expand Down
13 changes: 6 additions & 7 deletions tests/TestOfTestAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

/**
*
* Test TestAuthController class
*
* TestController isn't a real ThinkUp controller, this is just a template for all Controller tests.
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2011 Gina Trapani
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

class TestOfTestAuthController extends ThinkUpUnitTestCase {
/**
* Constructor
Expand Down Expand Up @@ -93,7 +92,7 @@ public function testIsLoggedIn() {
$this->assertEqual($v_mgr->getTemplateDataItem('app_title'), 'ThinkUp');

$this->assertEqual($results,
'<a href="/my/path/to/thinkup/index.php">ThinkUp</a>: Testing, testing, 123 | Logged in as me@example.com',
'<a href="/my/path/to/thinkup/">ThinkUp</a>: Testing, testing, 123 | Logged in as me@example.com',
"auth controller output when logged in");
}

Expand Down
13 changes: 6 additions & 7 deletions tests/TestOfTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
*
* You should have received a copy of the GNU General Public License along with ThinkUp. If not, see
* <http://www.gnu.org/licenses/>.
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

/**
*
* Test TestController class
*
* TestController isn't a real ThinkUp controller, this is just a template for all Controller tests.
* @license http://www.gnu.org/licenses/gpl.html
* @copyright 2009-2011 Gina Trapani, Guillaume Boudreau, Mark Wilkie
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
*/
require_once dirname(__FILE__).'/init.tests.php';
require_once THINKUP_ROOT_PATH.'webapp/_lib/extlib/simpletest/autorun.php';
require_once THINKUP_ROOT_PATH.'webapp/config.inc.php';

class TestOfTestController extends ThinkUpUnitTestCase {
/**
* Constructor
Expand Down Expand Up @@ -74,7 +73,7 @@ public function testControl() {
$this->assertEqual($v_mgr->getTemplateDataItem('test'), 'Testing, testing, 123');
$this->assertEqual($v_mgr->getTemplateDataItem('app_title'), 'ThinkUp');
$this->assertEqual($results, '<a href="'.$config->getValue('site_root_path').
'index.php">ThinkUp</a>: Testing, testing, 123 | Not logged in', "controller output");
'">ThinkUp</a>: Testing, testing, 123 | Not logged in', "controller output");
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/TestOfToggleActivePluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,31 @@ public function testBothParamsExistentInstance() {
$results = $controller->go();
$this->assertEqual($results, 1);
}

public function testBothParamsExistentInstanceDeactivateCallback() {
$webapp = Webapp::getInstance();
$webapp->registerPlugin('twitter', "TwitterPlugin");

//set up 2 active Twitter instances
$instance_builder_1 = FixtureBuilder::build('instances', array('network_username'=>'julie',
'network'=>'twitter', 'crawler_last_run'=>'-1d', 'is_activated'=>'1', 'is_public'=>'1'));
$instance_builder_2 = FixtureBuilder::build('instances', array('network_username'=>'john',
'network'=>'twitter', 'crawler_last_run'=>'-1d', 'is_activated'=>'1', 'is_public'=>'1'));

$instance_dao = DAOFactory::getDAO('InstanceDAO');
$active_instances = $instance_dao->getAllInstances("DESC", true, "twitter");
$this->assertEqual(sizeof($active_instances), 2);

$this->simulateLogin('me@example.com', true);
$_GET['pid'] = '1';
$_GET['a'] = '0';
$controller = new ToggleActivePluginController(true);
$results = $controller->go();
$this->assertEqual($results, 1);
$this->debug($results);

//make sure the 2 active Twitter instances got deactivated
$active_instances = $instance_dao->getAllInstances("DESC", true, "twitter");
$this->assertEqual(sizeof($active_instances), 0);
}
}
2 changes: 1 addition & 1 deletion tests/TestOfUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function testExistentUserWithInstance() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertEqual($v_mgr->getTemplateDataItem('controller_title'), 'User Details: someuser1');
$this->assertEqual($v_mgr->getTemplateDataItem('logo_link'), 'index.php');
$this->assertEqual($v_mgr->getTemplateDataItem('logo_link'), '');

$this->assertEqual($controller->getCacheKeyString(),
'user.index.tpl-me@example.com-someuser1-twitter-instancetestuser');
Expand Down
2 changes: 1 addition & 1 deletion tests/WebTestOfInstallation.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testSuccessfulInstallationAndAccountActivation() {
$this->setField('email', 'user@example.com');
$this->setField('pwd', 'secret');
$this->click("Log In");
$this->assertText('You have no accounts configured. Set up an account now');
$this->assertText('You have no services configured. Set up a service');

//Visit Settings page and assert content there
$this->click("Settings");
Expand Down
6 changes: 6 additions & 0 deletions tests/classes/class.TestFauxPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
*
*/
class TestFauxPlugin implements TestAppPlugin {
public function activate() {
}

public function deactivate() {
}

/**
* For testing purposes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function authControl() {
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail($this->getLoggedInUser());
$this->addToView('owner', $owner);
$this->addToView('logo_link', '');

//proces password change
if (isset($_POST['changepass']) && $_POST['changepass'] == 'Change password' && isset($_POST['oldpass'])
Expand Down
4 changes: 2 additions & 2 deletions webapp/_lib/controller/class.DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function control() {
' should appear to users who are not logged in.');
} else {
$config = Config::getInstance();
$this->addInfoMessage('You have no accounts configured. <a href="'.$config->getValue('site_root_path').
'account/?p=twitter">Set up an account now&rarr;</a>');
$this->addInfoMessage('You have no services configured. <a href="'.$config->getValue('site_root_path').
'account/">Set up a service like Twitter or Facebook now&rarr;</a>');
}
}
return $this->generateView();
Expand Down
2 changes: 1 addition & 1 deletion webapp/_lib/controller/class.ThinkUpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function __construct($session_started=false) {
$this->addToView('selected_instance_network', SessionCache::get('selected_instance_network'));
$this->addToView('selected_instance_username', SessionCache::get('selected_instance_username'));
$this->addToView('logo_link', 'index.php?u='. SessionCache::get('selected_instance_username')
.'&n='. SessionCache::get('selected_instance_network'));
.'&n='. urlencode(SessionCache::get('selected_instance_network')));
}
} catch (Exception $e) {
Utils::defineConstants();
Expand Down
19 changes: 18 additions & 1 deletion webapp/_lib/controller/class.ToggleActivePluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,24 @@ public function adminControl(){
if (!$this->is_missing_param) {
$is_active = ($_GET["a"] != 1)?false:true;
$plugin_dao = DAOFactory::getDAO('PluginDAO');
$this->addToView('result', $plugin_dao->setActive($_GET["pid"], $is_active));
$result = $plugin_dao->setActive($_GET["pid"], $is_active);
if ($result > 0 ) {
$plugin_folder = $plugin_dao->getPluginFolder($_GET["pid"]);
$webapp = Webapp::getInstance();
try {
$plugin_class_name = $webapp->getPluginObject($plugin_folder);
$p = new $plugin_class_name;
if ($is_active) {
$p->activate();
} else {
$p->deactivate();
}
} catch (Exception $e) {
//plugin object isn't registered, do nothing
//echo $e->getMessage();
}
}
$this->addToView('result', $result);
$this->view_mgr->clear_all_cache();
}
return $this->generateView();
Expand Down
13 changes: 6 additions & 7 deletions webapp/_lib/model/class.InstanceMySQLDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ public function delete($network_username, $network) {
}

public function getFreshestByOwnerId($owner_id) {
$q = " SELECT i.* , ".$this->getAverageReplyCount();
$q .= " FROM #prefix#instances AS i ";
$q .= " INNER JOIN #prefix#owner_instances AS oi ";
$q .= " ON i.id = oi.instance_id ";
$q .= " WHERE oi.owner_id = :owner ";
$q .= " ORDER BY crawler_last_run DESC";
$q .= " LIMIT 1";
$q = "SELECT i.* , ".$this->getAverageReplyCount()." ";
$q .= "FROM #prefix#instances AS i ";
$q .= "INNER JOIN #prefix#owner_instances AS oi ";
$q .= "ON i.id = oi.instance_id ";
$q .= "WHERE oi.owner_id = :owner AND i.is_active = 1 ";
$q .= "ORDER BY crawler_last_run DESC LIMIT 1";
$vars = array(
':owner'=>$owner_id
);
Expand Down
9 changes: 4 additions & 5 deletions webapp/_lib/model/class.PluginHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ protected function emitObjectMethod($trigger, $params = array()) {
}

/**
* Register an object plugin name
* Register an object plugin name.
* @param str $shortname Short name for plugin, corresponds to plugin folder name (like "twitter")
* @param str $objectname Object name (like "TwitterPlugin")
*/
public function registerPlugin($shortname, $objectname) {
$this->plugins[$shortname] = $objectname;
public function registerPlugin($short_name, $object_name) {
$this->plugins[$short_name] = $object_name;
}

/**
Expand All @@ -90,5 +90,4 @@ public function getPluginObject($shortname) {
}
return $this->plugins[$shortname];
}
}

}
2 changes: 1 addition & 1 deletion webapp/_lib/model/class.SmartyThinkUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct($config_array=null) {

$this->assign('app_title', $app_title);
$this->assign('site_root_path', $site_root_path);
$this->assign('logo_link', 'index.php');
$this->assign('logo_link', '');
}

/**
Expand Down
8 changes: 8 additions & 0 deletions webapp/_lib/model/interface.ThinkUpPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ interface ThinkUpPlugin {
* @return str HTML markup of configuration panel
*/
public function renderConfiguration($owner);
/**
* Activation callback, triggered when user deactivates plugin.
*/
public function activate();
/**
* Deactivation callback, triggered when user deactivates plugin.
*/
public function deactivate();
}
2 changes: 1 addition & 1 deletion webapp/_lib/view/post.index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ul id="top-level-sidenav"><br />
{if $post}
<ul class="side-subnav">
<li><a href="{$site_root_path}index.php?u={$selected_instance_username}&n={$selected_instance_network}">Dashboard</a></li>
<li><a href="{$site_root_path}index.php?u={$selected_instance_username}&n={$selected_instance_network|urlencode}">Dashboard</a></li>
<li{if $smarty.get.v eq ''} class="currentview"{/if}><a href="index.php?t={$post->post_id}&n={$post->network}">Post Replies&nbsp;&nbsp;&nbsp;</a></li>
{if $logged_in_user && $post->reply_count_cache && $post->reply_count_cache > 1}
<li id="grid_search_icon"><a href="#" class="grid_search" title="Search" onclick="return false;"><span>Search & Filter Replies</span></a></li>
Expand Down
7 changes: 7 additions & 0 deletions webapp/plugins/embedthread/model/class.EmbedThreadPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
* @copyright 2009-2011 Gina Trapani
*/
class EmbedThreadPlugin implements PostDetailPlugin {

public function activate() {
}

public function deactivate() {
}

public function getPostDetailMenuItems($post){
$data_tpl = Utils::getPluginViewDirectory('embedthread').'embedthread.inline.view.tpl';
$menus = array();
Expand Down
Loading

0 comments on commit 62c48f0

Please sign in to comment.