Piwik\Plugins\Installation\Rule_checkUserPrivileges::validateOwner PHP Method

validateOwner() public method

Checks that the DB user entered in the form has the necessary privileges for Piwik to run.
public validateOwner ( )
    public function validateOwner()
    {
        // try and create the database object
        try {
            $this->createDatabaseObject();
        } catch (Exception $ex) {
            if ($this->isAccessDenied($ex)) {
                return false;
            } else {
                return true;
                // if we can't create the database object, skip this validation
            }
        }
        $db = Db::get();
        try {
            // try to drop tables before running privilege tests
            $this->dropExtraTables($db);
        } catch (Exception $ex) {
            if ($this->isAccessDenied($ex)) {
                return false;
            } else {
                throw $ex;
            }
        }
        // check each required privilege by running a query that uses it
        foreach (self::getRequiredPrivileges() as $privilegeType => $queries) {
            if (!is_array($queries)) {
                $queries = array($queries);
            }
            foreach ($queries as $sql) {
                try {
                    if (in_array($privilegeType, array('SELECT'))) {
                        $db->fetchAll($sql);
                    } else {
                        $db->exec($sql);
                    }
                } catch (Exception $ex) {
                    if ($this->isAccessDenied($ex)) {
                        return false;
                    } else {
                        throw new Exception("Test SQL failed to execute: {$sql}\nError: " . $ex->getMessage());
                    }
                }
            }
        }
        // remove extra tables that were created
        $this->dropExtraTables($db);
        return true;
    }