Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New hook needed for UsersManager #2275

Closed
anonymous-matomo-user opened this issue Apr 6, 2011 · 13 comments
Closed

New hook needed for UsersManager #2275

anonymous-matomo-user opened this issue Apr 6, 2011 · 13 comments
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Milestone

Comments

@anonymous-matomo-user
Copy link

Following the same technique used with the Login plugin - which set's the Zend::Registry('auth') to an instance of the Login class - the same is also needed for the UsersManager, and then the instance stored in Zend::Registry should replace the static method UsersManger::get_instance called from the Piwik_UsersManager_Controller.
The reason is found here in summary: http://forum.piwik.org/read.php?3,74485,74594#msg-74591
Keywords: hooks UsersManager thirdparty-plugin-development

@mattab
Copy link
Member

mattab commented Apr 6, 2011

as this is specific to your app, we are happy to do it, but are you able to submit a patch & test it for this new feature?

@anonymous-matomo-user
Copy link
Author

I'm happy too to do it and will submit it for test once finished.. But it should be noted that your description for the Login plugin as "Can be easily replaced to introduce a new Authentication mechanism" is a bit misleading till this moment.

@anonymous-matomo-user
Copy link
Author

Attachment: plugins/UsersManager/API.php
API.php

@anonymous-matomo-user
Copy link
Author

I attached the API.php file with modifications needed to make the UsersManager overridable.

@mattab
Copy link
Member

mattab commented Apr 7, 2011

Will this work as well?


Index: plugins/UsersManager/API.php
===================================================================
--- plugins/UsersManager/API.php    (revision 4334)
+++ plugins/UsersManager/API.php    (working copy)
@@ -23,11 +23,16 @@
     */
    static public function getInstance()
    {
-       if (self::$instance == null)
-       {
-           self::$instance = new self;
+       try {
+           $instance = Zend_Registry::get('UsersManager_API');
+           if( !($instance instanceof Piwik_UsersManager_API) ) {
+               throw new Exception('UsersManager_API must inherit Piwik_UsersManager_API');
+           }
+       } catch (Exception $e) {
+           $instance = new self;
        }
-       return self::$instance;
+       Zend_Registry::set('UsersManager_API', $instance);
+       return $instance;
    }

    const PREFERENCE_DEFAULT_REPORT = 'defaultReport';

If you confirm this works with your plugin I can commit
also, do you mind posting a quick example of how you use it, I will add it as a comment. thx

@anonymous-matomo-user
Copy link
Author

Attachment: Tested
API.2.php

@anonymous-matomo-user
Copy link
Author

instead please refer to API.2.php attached
it was tested and passed

here is an example:

Register listener for some early hook like FrontController.initAuthenticationObject
and within the observer function:

Zend_Registry::set('UsersManager_API',Piwik_MyCustomUsersManager_API::getInstance());

the method Piwik_MyCustomUsersManager_API::getInstance() merely returns an instance of its class, which has methods overriden such as getUser and getUserByEmail etc... that looks inside other tables/data sources for users, instead of Piwik users table

@mattab
Copy link
Member

mattab commented Apr 13, 2011

(In [4434]) Fixes #2275 Thanks rahman for feedback!

@anonymous-matomo-user
Copy link
Author

velkommen

@anonymous-matomo-user
Copy link
Author

I'm looking forward to participating more. You can assign me tasks regarding Piwik bugs fixes/feature requests.

@mattab
Copy link
Member

mattab commented Apr 14, 2011

rahman, it is better if you grab the tasks that are interesting to you! we also look forward to seeing more patches

@anonymous-matomo-user
Copy link
Author

Okay, I will search the timeline for tasks. I'm kinda new to this so not sure how I will occasionally declare undertaking a request to avoid duplicate work with other developers.

@mattab
Copy link
Member

mattab commented Apr 14, 2011

in general, it is safe to work on any ticket unless

  • it was recently created and might be work in progress
  • it is already assigned to someone

Best to ask questions etc. No need to say "I'm going to work on this" because as we've seen in the past, most people who say that don't end up working on it so then it creates confusion ;)

@anonymous-matomo-user anonymous-matomo-user added this to the Piwik 1.3 milestone Jul 8, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Projects
None yet
Development

No branches or pull requests

2 participants