1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Calling applyThreadPrefix doesn't work as expected

Discussion in 'XenForo Development Discussions' started by Garani, Mar 14, 2014.

  1. Garani

    Garani Active Member

    I know that this is a bit strange, but let's see if someone gets what I am missing.

    I need to call XenForo_Model_InlineMod_Thread::applyThreadPrefix so that I can change the prefix of one or more threads.

    Yes, the user is authorized, and so is the forum for that particular prefix.

    I am calling the function from an extention of XenForo_ControllerPublic_InlineMod_Thread, so I am creating that class:

    PHP:
    $threadInlineModel XenForo_Model::create('DaVinciDigital_GuildManager_Extend_Model_InlineMod_Thread');
    Within the function I call it like this:

    PHP:
                $unchangedThreadsIds = array();
                
    $errorKey '';
                
    $options = array ();
                
    $prefixId = (string)$guilds[$thread['node_id']]['deguilded_prefix_id'];
                
    $threadInlineModel->applyThreadPrefix($threadDeguilded$prefixId$unchangedThreadIds$options$errorKey);
    On the first run, it does NOT work. Function is called, parameters are there and correct, but simply is does not write to DB, nor I get a moderator log as expected. So, something is off. Still I get no error ($errorKey) nor any unchanged thread ($unchangedThreadIds). Then out of the blue, once in a while, it works. Behavior is not coherent.

    I tried to mimic the function by creating a new datawriter, and that doesn't work either: it simply does not write to DB. The only solution I found was to raw write to the DB with this:

    PHP:
    $db XenForo_Application::get('db');

    $db->query("
            UPDATE xf_thread SET
            prefix_id = "
    .$guilds[$thread['node_id']]['deguilded_prefix_id'] . "
            WHERE thread_id = "
    .$thread['thread_id']);

    XenForo_Db::commit();
    (at the moment it is running within a loop, so it isn't efficient as it should).

    Any idea on what I may be missing?
     
  2. Garani

    Garani Active Member

    I think I am getting a step forward.

    applyThreadPrefix is failing because it is not passing the canEditThreads checks. In particular it is not passing canViewThreadAndContainer

    So I can't view... mmmm I have checked all permissions and they are correct. If I use the original InLine Mod selection of XenForo it works without any problem.

    I am missing something, but I can't quite catch what.
     
  3. Garani

    Garani Active Member

    Nothing, I just can't find the reason why I am failing canViewThreadAndContainer while the original XenForo doesn't fail.
     

Share This Page