add dropbox option to joomla on new user creation - joomla2.5

I'm using this plugin to permit the integration of dropbox into joomla.
When an user login te system create a folder in your dropbox account and everything works fine.
What I need is to add this option to the user creation page. I've tried to edit the save function in the controller com_users/controllers/user.php
JModel::addIncludePath (JPATH_ROOT . DS . 'components' . DS . 'com_dropbox' . DS . 'models');
$dropbox =& JModel::getInstance('dropbox', 'dropboxModel');
I need to pass values to the model here:
/**
* Creates a new folder
*
* This method returns the information from the newly created directory
*
* #param string $path
* #return stdclass
*/
public function createFolder($path="") {
$path= &Jfolder::makeSafe($path);
if (trim($path)=="")
{
//OK lets try to create the chroot
// $path=$this->dropbox->chroot;
}
$result = $this->auth->fetch('fileops/create_folder', array('path' => $this->dropbox->folder . '/' . $path, 'root' => $this->root),'POST');
return json_decode($result);
}
No results after various tries....
Please help me, thanks...!

You have to include the model file and call the function using the classname
Add the following line in the plugin:
jimport( 'joomla.filesystem.folder' );
require_once JPATH_ROOT . '/components/com_dropbox/models/filename.php';
dropboxModelfilename::functionname();

Related

GoAOP framework, can't get simple Aspect to work

I have been trying to play with the GoAOP library for awhile and have never successfully been able to get it to work. I have gone through the documentation several times and copied examples but haven't even been able to get them to work. All I am trying to achieve right now is a simple aspect.
I have several files as below:
app/ApplicationAspectKernel.php
<?php
require './aspect/MonitorAspect.php';
use Go\Core\AspectKernel;
use Go\Core\AspectContainer;
/**
* Application Aspect Kernel
*/
class ApplicationAspectKernel extends AspectKernel
{
/**
* Configure an AspectContainer with advisors, aspects and pointcuts
*
* #param AspectContainer $container
*
* #return void
*/
protected function configureAop(AspectContainer $container)
{
$container->registerAspect(new Aspect\MonitorAspect());
}
}
init.php
<?php
require './vendor/autoload.php';
require_once './ApplicationAspectKernel.php';
// Initialize an application aspect container
$applicationAspectKernel = ApplicationAspectKernel::getInstance();
$applicationAspectKernel->init(array(
'debug' => true, // Use 'false' for production mode
// Cache directory
'cacheDir' => __DIR__ . '/cache/', // Adjust this path if needed
// Include paths restricts the directories where aspects should be applied, or empty for all source files
'includePaths' => array(__DIR__ . '/app/')
));
require_once './app/Example.php';
$e = new Example();
$e->test1();
$e->test2('parameter');
aspect/MonitorAspect.php
<?php
namespace Aspect;
use Go\Aop\Aspect;
use Go\Aop\Intercept\FieldAccess;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\After;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\Around;
use Go\Lang\Annotation\Pointcut;
/**
* Monitor aspect
*/
class MonitorAspect implements Aspect
{
/**
* Method that will be called before real method
*
* #param MethodInvocation $invocation Invocation
* #Before("execution(public Example->*(*))")
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
$obj = $invocation->getThis();
echo 'Calling Before Interceptor for method: ',
is_object($obj) ? get_class($obj) : $obj,
$invocation->getMethod()->isStatic() ? '::' : '->',
$invocation->getMethod()->getName(),
'()',
' with arguments: ',
json_encode($invocation->getArguments()),
"<br>\n";
}
}
app/Example.php
<?php
class Example {
public function test1() {
print 'test1' . PHP_EOL;
}
public function test2($param) {
print $param . PHP_EOL;
}
}
When I run php init.php it does run but just prints without the output from MonitorAspect. I don't know if I'm defining the pointcut wrong in the #Before (I've tried several variations) or if I just have a fundamental misunderstanding of how this code is suppose to work.
Any help to point me in the right direction would be greatly appreciated.
GoAOP framework was designed to work with autoloader this means that it can handle only classes that were loaded indirectly via composer autoloader.
When you manually include you class via require_once './app/Example.php'; class is loaded by PHP immediately and could not be transformed by AOP, so nothing happens, because class is already present in the PHP's memory.
In order to make AOP working you should delegate class loading to the Composer and use PSR-0/PSR-4 standard for your classes. In this case, AOP will hook autoloading process and will perform transformation when needed.
See my answer about how AOP works in plain PHP that doesn't require any PECL-extentions for additional details about internals of the framework. This information should be useful for you.

cakephp 2.6 controller test case throwing MissingActionException on duplicate testAction()-call

I hope anyone can help me out with my testing environment.
my setup
I am implementing unit tests based on phpunit 3.7.22 with the cake release 2.6.9. Running on ubuntu 12.04 LTS with PHP 5.4.43-1 and postgresql 9.1.
I immplemented controller tests mocking cakes Auth Component to have a user in the session, since my tests depent on that. My controllers return json results, since its an API for a JS-based frontend. I call my controller methods using the testAction() call of a generated controller.
<?php
App::uses('RequesttypesController', 'Svc.Controller');
class RequesttypesWithResultControllerTest extends ControllerTestCase
{
public $fixtures = array(
'app.requesttype',
'app.user',
'app.privilege',
'app.groupsprivilege',
'app.groupsuser',
'app.groupscompany',
'app.company',
);
/**
* Mock the requesttype object so that it can return results depending on the desired outcome
*
* #see CakeTestCase::setUp()
*/
public function setUp()
{
parent::setUp();
$this->controller = $this->generate('Svc.Requesttypes', array(
'models' => array(
'Requesttype'
),
'components' => array(
'Auth' => array(
'user'
),
'Session',
'RequestHandler'
)
));
$this->controller->Auth->staticExpects($this->any())
->method('user')
->will($this->returnValue(array(
'id' => 123,
'username' => 'myTestUser',
'company' => 'myTestCompany',
'usertype_id' => '456',
))
);
$authResult = $this->controller->Auth->user();
}
public function tearDown()
{
parent::tearDown();
unset($this->controller);
}
/**
* A logged in user produces a number of requesttypes
*/
public function testLoggedInUser()
{
$result = $this->testAction('/svc/requesttypes/getMyRequesttypes', array('return' => 'vars'));
$this->assertNotEmpty($this->vars, 'Did not receive webservice response');
$this->assertTrue(isset($this->vars['data']['code']), 'Received invalid webservice response');
$this->assertEqual($this->vars['data']['code'], SvcAppController::RESPONSE_CODE_SUCCESS);
}
}
?>
This test passes without errors. Now I want to test my controller-action with different setups, for example users with a different usertype, from a different company, and so on. If I now create a second test-method in my RequesttypesWithResultControllerTest-class, calling the same testAction-url, i get a MissingActionException saying:
"Action RequesttypesController::() could not be found."
It seems that the testAction calls an empty controller-action, even if the action-url is passed as a parameter. I tried reinitializing the controller by nulling it and calling $this->generate() again, but this does not help either.
Of course I can help myself out by creating an own test-controller for every test ending up in a bunch of duplicate test-code, but this somehow seems not right to me.
Am I misusing the test-environment or how can this exception be explained? Any ideas?
Thanks in advance for sharing my headache!
After some further code debugging we finally found the error. We accidently changed the require statement of the last line of the /Config/routes.php file to a require_once because of some "Class already defined Exceptions" thrown in the test-environment.
Wrong routes.php:
require_once CAKE . 'Config' . DS . 'routes.php';
For the application itself that made no difference, since the routes are only needed to be initialized once per request. But in a test-environment, the routes are reinitialized several times, which was not possible anymore with the require_once include.
This is how the line is supposed to look like, which it does by default:
Correct routes.php:
require CAKE . 'Config' . DS . 'routes.php';

Joomla! 2.5 Can't change task from within top level controller of my component

I built a Joomla component a while ago which presents a disclaimer page immediately after logging in whereby the user has to select "I Agree" before going to the restricted site content.
The component is called com_rsdisclaimers and it has a master controller ~/coontroller.php and another (sub)controller in ~/controllers/rsdisclaimer.php defined as class RsdisclaimersControllerRsdisclaimer extends JControllerForm. The sub controller has a task/method called agree() which sets a session variable and redirects.
This all works okay in that a disclaimer is displayed and when the user clicks "agree", the sub controller task "agree" is called which sets a session variable and redirects. However I am trying to allow users to bypass this screen (component) if they have previously "agreed" to the terms. I am using JUser::getParam()/JUser::setParam() to do provide this persistance.
My design is to add logic at the component root file (~/rsdisclaimer.php) which the first checks to see if the user has the parameter already set. If so , I am trying to override and run the "agree" task straight away to handle the redirect rather than displaying the component's disclaimer page. However no matter what I do, changing the 'task' to 'agree' is simply not working on the first visit to the component after logging in on account that I and getting the master controller instead of the sub controller. How do I explicitly get a handle to the subcontroller so I can call the agree task?
Here is my top level php file:
<?php
/**
* #version 1.0.0
* #package com_rsdisclaimers
* #copyright Copyright (C) 2011 Chris Walsh. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
// Include dependancies
jimport('joomla.application.component.controller');
// NOTE TO SELF: If we called JRequest::getVar('task','') at this point, we
// might get a response of "rsdisclaimer.agree". However, when we
// call the same function after performing JController::getInstance('Rsdisclaimers')
// the task returned will now simply become 'agree'.
// 2014-11-20 | Chris Walsh
// Test to see if the user has previously 'agreed'...
$user = JFactory::getUser();
$accepted = $user->getParam('rsdisclaimer.accepted', '0');
echo "<pre>JCOMPONENT_BASE: accepted={$accepted}; task={$task}</pre>";
if($accepted == '1')
{
// Load the sub controller and jump straight to agree (redirects etc.)
// !! THIS IS NOT WORKING!! CAN'T GET THE SUB CONTROLLER
$task = 'agree';
$task = 'rsdisclaimer.agree';
$controller = JController::getInstance('Rsdisclaimers');
$controller->execute($task);
$controller->redirect();
}
else
{
// Execute the task
$controller = JController::getInstance('Rsdisclaimers');
$controller->execute(JRequest::getVar('task',''));
$controller->redirect();
}
The agree method in ~/controllers/rsdisclaimer.php works IF it actually gets called:
<?php
/**
* #version 1.0.0
* #package com_rsdisclaimers
* #copyright Copyright (C) 2011 Amy Stephen. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
jimport('joomla.application.component.controllerform');
/**
* #package Joomla.Site
* #subpackage com_rsdisclaimers
*/
class RsdisclaimersControllerRsdisclaimer extends JControllerForm
{
(snip)
/**
* Method to deal with the user selecting "agree".
*
* #return void
* #since 1.6.1
*/
function agree()
{
// Check for request forgeries.
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Set the session token which the plugin 'realsensedisclaimer' will check for
$session = JFactory::getSession();
$session->set('RealsenseDisclaimer', true);
// Set the agree parameter if not already set so we don't ask again
$user = JFactory::getUser();
$accepted = $user->getParam('rsdisclaimer.accepted', '0');
if($accepted == '0')
{
$user->setParam('rsdisclaimer.accepted', '1');
$user->setParam('rsdisclaimer.acceptedDate', '2014-11-20');
$accepted = $user->getParam('rsdisclaimer.accepted', '0');
}
// Redirect them to the nominated location
$app = JFactory::getApplication();
$url = 'index.php?option=com_content&view=article&id=1110&Itemid=101';
$app->redirect(JRoute::_($url, false));
}
(snip)
}
Can anyone advise how I can get a handle to the sub controller rather than the master controller?
Thanks.

SoapClient does not recognize a function I am seeing in WSDL

I have a simple webservice in symfony2 that is working perfectly. I have added a new method, however, strangely, that method is not recognized, even when I see it in the WSDL definition.
Please load: WSDL definition
Method is called GetHoliday
The controller that executes that method is the following:
public function getHolidayAction() {
date_default_timezone_set('America/Santiago');
$request = $this->getRequest();
$client = new \SoapClient('http://' . $request->getHttpHost() . $request->getScriptName() . '/feriados?wsdl');
$year = $request->get('year');
$month = $request->get('month');
$day = $request->get('day');
$types = $client->__getFunctions();
var_dump($types);
die();
$result = $client->GetHoliday('8cd4c502f69b5606a8bef291deaac1ba83bb7727', 'cl', $year, $month, $day);
echo $result;
die();
}
After the call to __getFunctions call, GetHoliday method is missing.
If you want to see the __getFunctions response, please load online site
Enter any date in the input field. The response will appear in red.
The most curious thing, is that this works in my development machine which also has RedHat operating system (my hosting is HostGator).
Any help will be appreciated,
Finally, the problem was that the WSDL was being cached.
To make the first test, I used
$client = new \SoapClient('http://' . $request->getHttpHost() . $request->getScriptName() . '/feriados?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE) );
To instantiate SoapClient. That way, it worked. so to get rid of WSDL_CACHE_NONE parameter, I deleted all files that start with wsdl in /tmp folder.
Regards,
Jaime

ZF, ZFDoctrine and PHPUnit setup

Does anyone here use Zend Framework, ZFDoctrine and PHPUnit together?
How to rebuild the database on each test run?
How to separate local/production/testing environments?
Would you share your unit testing setup?
I have been trying something like that:
// /tests/bootstrap.php
// ... setup paths and constants here
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap('doctrine');
$provider = new ZFDoctrine_Tool_DoctrineProvider;
$provider->generateModelsFromYaml();
//$provider->buildProject(true);
But this ends in:
Notice: Constant APPLICATION_PATH already defined in /home/user/www/library/ZendFramework/1.10.7/library/Zend/Tool/Project/Context/Zf/BootstrapFile.php on line 106
Fatal error: Call to a member function getResponse() on a non-object in /home/user/www/library/zf-doctrine/library/ZFDoctrine/Tool/DoctrineProvider.php on line 271
Models are not generated.
I get similar errors running:
$provider->createDatabase();
But in this case database is created.
The other provider commands do not work.
The solution:
$provider = new ZFDoctrine_Tool_DoctrineProvider;
$registry = new Zend_Tool_Framework_Registry;
$provider->setRegistry($registry);
#$provider->buildProject(true);
If anybody knows a better approach, please correct me.
I haven't used ZFDoctrine, but just plain Doctrine 1.2. I don't know if my solution is better but I figured I post if any1 is interested, here's the bootstrap.php in my tests folder:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
// Define application environment
/**
* In the application.ini:
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
doctrine.dsn = "mysql://my_user:passwd#localhost/my_phpunit_test_db"
*/
define('APPLICATION_ENV', 'testing');
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path()
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/../configs/application.ini'
);
$application->getBootstrap()->bootstrap();
// Can run out if too small
ini_set('memory_limit', '512M');
// Get the doctrine settings
$config = $application->getOption('doctrine');
$cli = new Doctrine_Cli($config);
$cli->run(array("doctrine", "build-all-reload","force"));
The key here is actually the last line that rebuilds all databases creating a clean environment for each testing.