Writing plugins for v4

Discussion in 'aMember Pro v.4' started by igpman, Oct 28, 2011.

  1. igpman

    igpman aMember Pro Customer

    Joined:
    Mar 17, 2010
    Messages:
    72
    Is there a guide anywhere for writing plugins for aMember v4? I need to integrate my CMS but am not sure where to start.

    Thanks.
  2. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    @igpman:

    There are a few plugins that ship with the aMember default installation that you can to for reference (Facebook, Wordpress,etc)..

    In addition, this URL will walk you through a wizard to create a plugin skeleton for you:

    http://yourdomain.com/amember/admin-plugin-maker
  3. igpman

    igpman aMember Pro Customer

    Joined:
    Mar 17, 2010
    Messages:
    72
    Thanks, that's a helpful start. :) It would be nice if there was a more comprehensive documentation, but this should be enough to get by.
  4. igpman

    igpman aMember Pro Customer

    Joined:
    Mar 17, 2010
    Messages:
    72
    I used this to create a skeleton, though the skeleton caused fatal errors which I have fixed and reported in the v4 bugtracker. I get the impression that out of the box this should be able to add users to my third-party database. The comments in the skeleton file say the first step is to test if adding users to the third-party database works, which it doesn't. I've looked in the existing plugin files and their contents seem very similar.

    Everything is configured correctly as far as I can see but adding users doesn't work, and if I attempt a database rebuild it produces this error:

    Code:
    Rebuilding Mycms Db... An internal error happened in the script, please contact webmaster for details. Please contact webmaster: ****@*******.com. Incorrect response received. Stopped!
    The aMember error log states:

    Am_Protect_Table->getGroups() is not implemented
    Code:
    Exception Am_Exception_NotImplemented
    Am_Protect_Table->getGroups [ library\Am\Protect\Databased.php : 548 ]
    Am_Protect_Databased->isAdmin [ library\Am\Protect\Databased.php : 568 ]
    Am_Protect_Databased->canUpdate [ library\Am\Protect\Databased.php : 687 ]
    Am_Protect_Databased->batchProcess
    call_user_func_array [ library\Am\App.php : 1772 ]
    Am_BatchProcessor->run [ library\Am\Protect\Databased.php : 664 ]
    Am_Protect_Databased->onRebuild
    call_user_func [ application\default\controllers\AdminRebuildController.php : 227 ]
    AdminRebuildController->doAction [ library\Am\Controller.php : 139 ]
    Am_Controller->_runAction [ library\Am\Controller.php : 116 ]
    Am_Controller->dispatch [ library\Zend\Controller\Dispatcher\Standard.php : 295 ]
    Zend_Controller_Dispatcher_Standard->dispatch [ library\Zend\Controller\Front.php : 954 ]
    Zend_Controller_Front->dispatch [ library\Am\App.php : 1329 ]
    Am_App->run [ index.php : 41 ]
    Any idea what's wrong?
  5. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    If you copy/paste the plugin here, I can try to say what's wrong.
  6. igpman

    igpman aMember Pro Customer

    Joined:
    Mar 17, 2010
    Messages:
    72
    Thanks. I have put it on pastebin:
    http://pastebin.com/uj0MZqDQ

    I'm sure I have the database configured correctly. The plugin even detects my user groups just fine and I can select the default group for new users etc.

    EDIT: If you want to see the structure of my user table and the field types I can PM it to you.
  7. igpman

    igpman aMember Pro Customer

    Joined:
    Mar 17, 2010
    Messages:
    72
  8. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    You have choosed group mgmt mode as
    protected $groupMode = Am_Protect_Databased::GROUP_SINGLE;
    but table definition does not define field where group_id is set.

    Quick example:
    say the third-party script has the following structure:
    groups table
    id​
    title​
    sample for records:​
    1 Registered Member​
    2 Paid Customer​
    3 Administrator​
    ...............​

    users table
    id​
    username​
    password​
    ......​
    group_id - refers to 'id' field of 'groups' table​
    .......​

    In this case, you must add to your pastebin after line 71:
    PHP:
    array(Am_Protect_Table::FIELD_GROUP_ID'group_id'),
    then aMember knows where to fetch group id for user record, and exception will not be thrown.
  9. igpman

    igpman aMember Pro Customer

    Joined:
    Mar 17, 2010
    Messages:
    72
    Thanks. That stopped the error from showing up.

    Unfortunately it still won't add users to the third-party database when they are added in aMember though. The same is true of trying a database rebuild for the plugin. Am I missing something?

    Here is the latest code: http://pastebin.com/9PxR0K4F

    I made sure to also add group_id to the $guessFieldsPattern array. In case you're wondering, that actually is the name of my user group field, coincidentally.
  10. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    I wonder, did you setup integration between aMember and third-party script?
    aMember CP -> Protect Content -> Integrations ?
    If integration was not enabled for your plugin(if you didn't assign aMember products to groups in your third-party script) aMember will not create users in third-party script.
  11. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    You have to configure integration at aMember CP -> Manage Content -> Integrations

    Users will be added to your helpdesk once they complete payment (or you add "Access" record to user manually on "Invoices" screen)
  12. igpman

    igpman aMember Pro Customer

    Joined:
    Mar 17, 2010
    Messages:
    72
    I searched for "Manage Content" in the ACP and couldn't find it. But I have already set up and enabled the plugin since the first post. I will explain how to avoid any confusion:

    I did this in Configuration -> Setup/Configuration -> Plugins, where I added my plugin to list of "Integration Plugins" and clicked save. Then my plugin appeared as a tab button at the top, so I clicked it and configured the database connection and table prefix etc.

    I know this worked because under "Mycms Integration Settings" on the plugin configuration I am able to select user groups from my tables in Mycms, which demonstrates the link was successful. The settings are saved also, and remain there every time I check them again.

    The next step in the documentation of the plugin says I should be able to create users and they will be added to the third-party tables. Yet when I add a user or attempt to Rebuild the database in aMember, the user is not added to the Mycms user table.
  13. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    Alex means "protect content". have a look to screenshot.

    Attached Files:

  14. igpman

    igpman aMember Pro Customer

    Joined:
    Mar 17, 2010
    Messages:
    72
    Thanks, that solved it. I don't remember having to do that in v3 when I made a plugin.

    Well, now I can get on with integrating the login etc. Thanks again.
  15. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    In v3 that setting was in different place, in product config. (amember CP -> manage products -> Edit Product)

Share This Page