Personal computing discussed

Moderators: SecretSquirrel, just brew it!

 
|FN|Steel
Minister of Gerbil Affairs
Topic Author
Posts: 2160
Joined: Wed Dec 26, 2001 7:00 pm
Location: Kansas

PHP(7) Help

Wed Sep 14, 2016 3:43 pm

I almost had what was going wrong her a few weeks back, but I've lost my logic path with a gazillion things going on. I think I recall reading that it had something to do with the way newname is being returned after being declared. It's a snippet from a Roundcube plugin and the only one tossing up a warning in my log file. Can anyone suggest how to restate it? Thank you!

function rename_group($gid, $newname) { return $newname; }
Sucking down the easy flowing milk from society's warm breasts.
 
DancinJack
Grand Gerbil Poohbah
Posts: 3186
Joined: Sat Nov 25, 2006 3:21 pm
Location: Kansas

Re: PHP(7) Help

Wed Sep 14, 2016 3:54 pm

Are you sure it's that line?
i7 6700K - Z170 - 16GiB DDR4 - GTX 1080 - 512GB SSD - 256GB SSD - 500GB SSD - 3TB HDD- 27" IPS G-sync - Win10 Pro x64 - Ubuntu/Mint x64 :: 2015 13" rMBP Sierra :: Canon EOS 80D/Sony RX100
 
Redocbew
Gold subscriber
Graphmaster Gerbil
Posts: 1350
Joined: Sat Mar 15, 2014 11:44 am

Re: PHP(7) Help

Wed Sep 14, 2016 3:56 pm

Yeah, we need a little more to go on here.  That function you included does absolutely nothing.
Do not meddle in the affairs of archers, for they are subtle and you won't hear them coming.
 
|FN|Steel
Minister of Gerbil Affairs
Topic Author
Posts: 2160
Joined: Wed Dec 26, 2001 7:00 pm
Location: Kansas

Re: PHP(7) Help

Wed Sep 14, 2016 4:06 pm

Well, the literal line being returned in the log file is the beginning of the entire piece of code, followed by this particular line. I'm just gonna paste it, it's short enough:

<?php

/**
 * Specialised Global Addressbook Contacts Class Backend!
 *
 * @author Michael Daniel Telatynski <postmaster@webdevguru.co.uk>
 * @copyright 2015 Web Development Guru
 * @license http://bit.ly/16ABH2R
 * @license MIT
 *
 * @version 2.5.0
 */
class sql_global_backend extends rcube_addressbook {

    public $group_id, $groups = false;
    public $primary_key = 'ID';
    public $readonly = true;

    private $filter, $result, $name;

    public function __construct($name) {
        $this->ready = true;
        $this->name  = $name;
    }

    public function get_name() { return $this->name; }
    public function set_search_set($filter) { $this->filter = $filter; }
    public function get_search_set() { return $this->filter; }

    public function reset() {
        $this->result = null;
        $this->filter = null;
    }

    public function get_record($id, $assoc=false) {
        $db = rcube::get_instance()->db;
        $db->query('SELECT * FROM global_addressbook WHERE `ID`=?', $id);
        if ($sql_arr = $db->fetch_assoc()) {
            $sql_arr['email'] = explode(',', $sql_arr['email']);
            $this->result = new rcube_result_set(1);
            $this->result->add($sql_arr);
        }

        return $assoc && $record ? $record : $this->result;

    }

    public function list_records($cols=null, $subset=0) {
        $this->result = $this->count();
        $db = rcube::get_instance()->db;

        if (empty($this->group_id)) {

            switch ($this->name) {
                case 'global':
                    $cf = rcmail::get_instance()->config->get('_sql_gb_data_allowed', array('*'));
                    $fc = rcmail::get_instance()->config->get('_sql_gb_data_hidden', array());
                    if ($cf === array('*')) {
                        $cf = array();
                    } else { $x[] = 'domain IN (' . $db->array2list($cf) . ')'; }
                    if ($this->filter)  { $x[] = '(' . $this->filter .')'; }
                    if (count($fc) > 0) { $x[] = 'domain NOT IN (' . $db->array2list($fc) . ')'; }
                    $x = count($x) > 0 ? (' WHERE ' . implode(' AND ', $x)):'';
                    $db->query('SELECT * FROM global_addressbook' . $x);
                    break;

                case 'domain':
                    $x = $this->filter ? (' (' . $this->filter . ') AND '):' ';
                    $db->query('SELECT * FROM global_addressbook WHERE' . $x . 'domain=?', rcmail::get_instance()->user->get_username('domain'));
                    break;

                default:
                    $d = rcmail::get_instance()->config->get('_sql_supportbook', array());
                    $f = array_flip(sql_global_addressbooks::ac($d, 0));
                    array_shift($z = $d[$f[$this->name]]);
                    if ($this->filter) { $x[] = '(' . $this->filter .')'; }
                    if (count($z) > 0) { $x[] = 'domain IN (' . $db->array2list($z) . ')'; }
                    $x = count($x)> 0 ? (' WHERE ' . implode(' AND ', $x)):'';
                    $db->query('SELECT * FROM global_addressbook' . $x);
            }

        } else {
            $x = $this->filter ? (' (' . $this->filter . ') AND '):' ';
            $db->query('SELECT * FROM global_addressbook WHERE' . $x . 'domain=?', $this->group_id);
        }

        while ($ret = $db->fetch_assoc()) {
            $ret['email'] = explode(',', $ret['email']);
            //$names = explode(' ', $ret['name']);
            //$ret['surname'] = array_push($names);
            //$ret['firsname']= implode(' ', $names);
            $this->result->add($ret);
        }
        return $this->result;

    }

    function list_groups($search = null, $mode=0) {
        if (!$this->groups) { return array(); }
        $rc = rcmail::get_instance();
        $cf = $rc->config->get('_sql_gb_data_allowed', array('*'));
        $fc = $rc->config->get('_sql_gb_data_hidden', array());

        if ($search) {
            switch (intval($mode)) {
                case 1:
                    $x = $rc->db->ilike('domain', $search);
                    break;
                case 2:
                    $x = $rc->db->ilike('domain', $search . '%');
                    break;
                default:
                    $x = $rc->db->ilike('domain', '%' . $search . '%');
            }
            $x = ' WHERE ' . $x . ' ';
        } else { $x = ' '; }

        if ($cf === array('*')) {
            $cf = array();
            $rc->db->query('SELECT domain FROM global_addressbook' . $x . 'GROUP BY domain');
            while ($ret = $rc->db->fetch_assoc()) {$cf[] = $ret['domain']; }
        }

        $co = array();
        foreach (array_diff($cf, $fc) as $v) { $co[] = array('ID' => $v, 'name' => $v); }
        //file_put_contents('/var/www/test.log', print_r([$co, $search, $mode, $this->groups, $this->name, $this->group_id], true));
        return $co;

    }

    public function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array()) {
        if (!is_array($fields)) { $fields = array($fields); }
        if (!is_array($required) && !empty($required)) { $required = array($required); }


        $db = rcube::get_instance()->db;
        $where = array();
        $mode = intval($mode);
        $WS = ' ';

        foreach ($fields as $idx => $col) {

            if ($col == 'ID' || $col == $this->primary_key) {
                $ids     = !is_array($value) ? explode(',', $value) : $value;
                $ids     = $db->array2list($ids, 'integer');
                $where[] = 'c.' . $this->primary_key.' IN ('.$ids.')';
                continue;
            } else if ($col == '*') {
                    $words = array();
                    foreach (explode($WS, rcube_utils::normalize_string($value)) as $word) {
                        switch ($mode) {
                            case 1: // Strict
                                $words[]='(' . $db->ilike('name', $word . '%')
                                    . ' OR ' . $db->ilike('email',$word . '%')
                                    . ' OR ' . $db->ilike('name', '%' . $WS . $word . $WS . '%')
                                    . ' OR ' . $db->ilike('email','%' . $WS . $word . $WS . '%')
                                    . ' OR ' . $db->ilike('name', '%' . $WS . $word)
                                    . ' OR ' . $db->ilike('email','%' . $WS . $word). ')';
                                break;

                            case 2: // Prefix
                                $words[]='(' . $db->ilike('name', $word . '%')
                                    . ' OR ' . $db->ilike('email',$word . '%')
                                    . ' OR ' . $db->ilike('name', '%' . $WS . $word . '%')
                                    . ' OR ' . $db->ilike('email','%' . $WS . $word . '%') . ')';
                                break;

                            default: // Partial
                                $words[]='(' . $db->ilike('name', '%' . $word . '%')
                                    . ' OR ' . $db->ilike('email','%' . $word . '%') . ')';
                                break;
                        }
                    }
                    $where[] = '(' . join(' AND ', $words) . ')';
            //} else {
            } elseif ($col !== 'firstname' && $col !== 'surname') {
                $val = is_array($value) ? $value[$idx] : $value;

                switch ($mode) {
                    case 1: // strict
                        $where[] = '(' . $db->quote_identifier($col) . ' = ' . $db->quote($val)
                            . ' OR ' . $db->ilike($col, $val . $AS . '%')
                            . ' OR ' . $db->ilike($col, '%' . $AS . $val . $AS . '%')
                            . ' OR ' . $db->ilike($col, '%' . $AS . $val) . ')';
                        break;
                    case 2: // prefix
                        $where[] = '(' . $db->ilike($col, $val . '%')
                            . ' OR ' . $db->ilike($col, $AS . $val . '%') . ')';
                        break;
                    default: // partial
                        $where[] = $db->ilike($col, '%' . $val . '%');
                }
            }

            if (!empty($where)) {
                $this->set_search_set(join(is_array($value) ? ' AND ' : ' OR ', $where));
                /*if ($select) {
                    $this->list_records(null, 0, $nocount);
                } else { $this->result = $this->count(); */
            }

        }


        return $this->list_records();
    }
    function get_group($group_id) { return $this->groups ? array('ID' => $group_id, 'name' => $group_id) : null; }
    public function count() { return new rcube_result_set(1, ($this->list_page-1) * $this->page_size); }
    public function get_result() { return $this->result; }
    public function set_group($gid) {
        $this->group_id = $gid;
        $this->cache = null;
    }
    function create_group($name) { return false; }
    function delete_group($gid) { return false; }
    function rename_group($gid, $newname) { return $newname; }
    function add_to_group($group_id, $ids) { return false; }
    function remove_from_group($group_id, $ids) { return false; }

}



The error message is:
Sep 14 13:50:10 mail roundcube: PHP Warning:  Declaration of sql_global_backend::rename_group($gid, $newname) should be compatible with rcube_addressbook::rename_group($gid, $newname, &$newid) in /var/www/roundcubemail-1.2.0/plugins/sql_global_addressbooks/sql_global_backend.php on line 13

Line 13 =
class sql_global_backend extends rcube_addressbook { 

So the beginning of the whole thing, right?

Right now I'm looking at thethis page. I think what it's suggesting is that I declare those two values null there, but I don't know enough to know for sure. My next step would just be to do that and see if it breaks, but I'll wait on you guys. :)
Sucking down the easy flowing milk from society's warm breasts.
 
Redocbew
Gold subscriber
Graphmaster Gerbil
Posts: 1350
Joined: Sat Mar 15, 2014 11:44 am

Re: PHP(7) Help

Wed Sep 14, 2016 4:23 pm

You've got a child class(sql_global_backend) that is overriding a method from it's parent class(rcube_addressbook) but is defining it with a different set of parameters.  The method from the parent class has three, but the child class is defined with two.  PHP thinks something weird is going on there, because the only reason to override a class method is if you want to preserve the original intention but have it done with slightly different mechanics.  Otherwise, just write new method.
Do not meddle in the affairs of archers, for they are subtle and you won't hear them coming.
 
|FN|Steel
Minister of Gerbil Affairs
Topic Author
Posts: 2160
Joined: Wed Dec 26, 2001 7:00 pm
Location: Kansas

Re: PHP(7) Help

Wed Sep 14, 2016 4:40 pm

Heh, simply changing the 
rename_group($gid, $newname)

to
rename_group($gid, $newname, &$newid)

Did the trick. Goodbye 120 MB log files!

lol thanks guys!
Sucking down the easy flowing milk from society's warm breasts.

Who is online

Users browsing this forum: No registered users and 2 guests