R_J
R_J

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Badges

Try Vanilla Forums Cloud product

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Update for critical security issue in PHPMailer included in release Vanilla 2.3.1

R_J · Cheerleader & Troubleshooter · Moderator

About

Username
R_J
Location
Munich
Joined
Visits
3,151
Last Active
Roles
Moderator, Developer, Community Developers
Points
3,739
Location
Munich
GitHub
R-J
Country
Germany
Badges
30
  • Re: Creating query var fore tpl 2.3.1

    One additional comment: if you do one database query very often, you have to think about improving that. You should save that information directly to the user table and afterwards you would be able to access it with e.g. Gdn::session()->User->GroovyID

    Here comes something which I'm not able to test, but I think it should work. I will need a provider name and since I don't know it, I will call it "Groovy". You would have to replace that string in the code...

    public function gdn_auth_authSuccess_handler($sender, $args) {
        $groovyID = Gdn::sql()
            ->select('ForeignUserKey')
            ->from('UserAuthentication')
            ->where(
                [
                    'UserID' => $args['UserData']['UserID'],
                    'ProviderKey' => 'Groovy'
                ]
            )
            ->get()
            ->value('ForeignUserKey');
        Gdn::userModel()->saveAttribute(
            $args['UserData']['UserID'],
            'GroovyID',
            $groovyID
        );
    }
    

    In theory when a user successfully authenticates, the current foreign key is written to the attributes column in the user table. Values of that column are accessible like any other column. Therefore $user->GroovyID would shouw the result without an addtional database query.

    But it is all untested. It might fail, but I think it is probable and if you want to show that info quite often throughout your forum, caching the value is a must!


    You might not be able to simply use that if you have a lot of users already using this authentication provider. The first time this would work is when they have to authenticate on your forum.
    I don't know if there is a simple way to force every user to re-authenticate. A workaround would be to write a small plugin which adds all external ids to the user table. That could be run once as a start. In futuretimes the snippet above should take care of the rest.

    vrijvlinder
  • Re: multiple duplicates of "roles & permission" levels

    No, you shouldn't have used the porter, but if you had, it could be what has causes the described problem ;)

    First of all you should find out if there are duplicates in the database or if you only see duplicates. Please use this query on your database and show the results here (if there are duplicates): SELECT * FROM GDN_Role

    If there are no duplicates in the database but only in the dashboard view, you have some kind of problem that I'm not sure how to even debug.

    But if you have duplicates in the database, you would have to look for users in one of those duplicate roles. The expected result for the query above would be similar to this:
    RoleID 2, Guest
    RoleID 3, Unconfirmed
    RoleID 4, Applicant
    RoleID 8, Member
    RoleID 16, Admin
    RoleID 32, Moderator

    Therefore, if you run the query SELECT * FROM GDN_UserRole WHERE RoleID NOT IN (2,3,4,8,16,32) you would see all users not having the standard role.

    If there are no results for the query, those phantom roles are not used anywhere and therefore can be deleted.

    Deleting anything is always risky. Please make a backup of your database!. You can change the above query to SELECT * FROM GDN_UserRole WHERE RoleID NOT IN (2,3,4,8,32) which should show you all admins. This way you can be sure that the query is working as expected. And then you should be able to delete those roles without any bad consequences. Just be sure to delete the addtional roles. Deleting them by sql to be sure not to delete a default RoleID might be more safe in this case.

    Caylus
  • Re: Wrong count of discussions displayed for a category

    Can you run a database query like e.g.

    SELECT *
    FROM `GDN_Discussion`
    WHERE CategoryID = X
    

    where "X" is the ID of that category.

    That should show 5 discussions and should give a hint on the "missing" discussion.

    hgtonightCaylus
  • Re: How to migrate 2.3.1 to 2.4.x

    @terabytefrelance said:
    @K17 I want to start from a clean 2.4.X installation, and restore the database and test and adapt the plugins to the new version, and correct any errors found, and leave a guide of this process in the forum.

    Regards,

    It's a great idea to start testing and if you give feedback, that would be helpful! If you come across some Vanilla bugs, the best way to report those bugs by filing an issue on GitHub.

    You can do a clean installation and simply change the database credentials in the config.php afterwards to point to a copy of your database. If I understood it correctly that's your plan.

    There are some site specific settings in the config.php which you will loose when you go this way, but that should be no problem.

    K17
  • Re: can I add a criteria to a module?

    Great question! =)

    The {module... syntax is a custom Smarty function. If you look it up you will find that it points towards class Theme, method module. In that method you will find the following code

                    $Properties = array_merge($ControllerProperties, $Properties);
    
                    foreach ($Properties as $Name => $value) {
                        // Check for a setter method
                        if (method_exists($Module, $method = 'set'.ucfirst($Name))) {
                            $Module->$method($value);
                        } else {
                            $Module->$Name = $value;
                        }
                    }
    

    Without further testing, I would expect that in your example {module name="PromotedContentModule" Selector="role" ContentType="discussions" Selection="administrator" Limit="3" BodyLimit="90"} you would need a module which implemets the following methods:

    • setSelector
    • setContentType
    • setSelection
    • setLimit
    • setBodyLimit

    If that methods are not implemented, you should be able to access the values directly as properties of your module.


    Oh wait, your question has been the other way around. But then it is just the other way around:

         public function discussionController_beforeFirstComment_handler($sender) {
                $promotedContentModule = new PromotedContentModule($sender);
    
                if (method_exists('setSelector')) {
                    $promotedContentModule->setSelector('role');
                } else {
                    $promotedContentModule->Selector = 'role';
                }
                //Repeat for every parameter...
    
                echo $promotedContentModule->toString();
            }
    
    AjansKartalhgtonight