Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Problem with Setup method in Plugin

edited November 2010 in Vanilla 2.0 - 2.8
For some reason this code is not running correctly.

public function Setup() { // Create db table. gc_cals (name,feedid, url,days) $s = Gdn::Structure(); $s->Table('Cals') ->PrimaryKey('calID') ->Column('name', 'varchar(255)') ->Column('feedid', 'varchar(128)') ->Column('days', 'int(3)') ->Column('url', 'varchar(255)') ->Set(FALSE, FALSE); $s->Insert('Cals', array( 'name' => 'This Weeks Games', 'feedid' => 'calgames', 'days' => 8, 'url' => 'group.calendar.google.com' )); SaveToConfig('Plugins.GoogleCalendar.Enabled', TRUE); }

This is in a file called default.php in a plugin.

Comments

  • Options
    The file is run for the plugin as the render_before code is run on page generation but the setup is not.
  • Options
    TimTim Operations Vanilla Staff
    This code should only fire once - immediately following the plugin's activation. Is that when you're expecting it to happen?

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • Options
    Yes.
    The insert is there as is testing. In the final plugin there will be a way to configure it in the dashboard.

    The table and record are not inserted whent he plugin is enabled.
  • Options
    TimTim Operations Vanilla Staff
    In your index.php file, right near the beginning (after the GPL stuff) put this:
    define('DEBUG', TRUE);

    Then try disable / enable the plugin and see if you have errors.

    Vanilla Forums COO [GitHub, Twitter, About.me]

  • Options
    Tried doing that but as soon as i do i get a page not found error on all none dashboard pages.
    Nothing shows up on the debugger plugin either.
    Currently running 2.011 (cant upgrade for a few weeks)
  • Options
    LincLinc Detroit Admin
    $s is an instance of Structure. To do an insert, I think you need an SQL object:
    $Database = Gdn::Database(); $SQL = $Database->SQL();
    Then you can do
    $SQL->Insert( ... );
  • Options
    Ive tried doing that but the database table is still not created. Ive checked via phpmyadmin.
  • Options
    any ideas?
  • Options
    LincLinc Detroit Admin
    edited November 2010
    Delete the plugin, delete your ini files in the cache folder, delete it from your config.php file (remove the line where it's stored in the EnabledPlugins array). Then re-upload it and re-enable it. That's all I've got.
  • Options
    @Lincoln @Tim Maybe a bit offtopic, but are there methods that are called when the plugin is disabled / removed? I remember seeing in the code in some previous version that in Gdn_IPlugin there are commented function declarations:
    /** * These methods are invoked if present, but are not required and will be silently ignored * if they do not exist. */ // public function OnLoad() - Called as the plugin is instantiated (each page load) // public function OnDisable() - Called as the plugin is disabled // public function CleanUp() - Called as the plugin is removed

    I can read the comments, but are these really working?

    /cd
  • Options
    LincLinc Detroit Admin
    I have no reason to doubt that they do, but I have never had use for them myself.
  • Options
    Deleted the ini files.
    Removed the config settings and it now runs correctly. The problme was my previous version did not remove itself from the config settings.
  • Options
    LincLinc Detroit Admin
    Yay!
Sign In or Register to comment.