Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access protected property #3

Open
cjstone opened this issue Mar 4, 2019 · 6 comments · May be fixed by #6
Open

Cannot access protected property #3

cjstone opened this issue Mar 4, 2019 · 6 comments · May be fixed by #6
Labels

Comments

@cjstone
Copy link

cjstone commented Mar 4, 2019

Yourls 1.7.4
Ubuntu 18.04
MySQL 5.7.25
php 7.2.15

Loading the plugin produces this error:

(I can get the plugin to load by not using the user/cache.php file, and caching does seem to work, but the same error is produced when I attempt to edit or delete a URL.)

Next Error: Cannot access protected property YOURLS\Database\YDB::$infos in /var/www/xxxxxx/user/plugins/yapcac he/plugin.php:139 Stack trace: #0 /var/www/xxx in /var/www/xxxxxx/user/plugins/yapcache/plugin.php on line 139 [04-Mar-2019 19:25:56 UTC] PHP Fatal error: Uncaught Error: Cannot access protected property YOURLS\Database\YDB ::$infos in /var/www/xxxxxx/user/plugins/yapcache/plugin.php:139 Stack trace: #0 /var/www/xxxxxx/includes/functions-plugins.php(152): yapc_pre_get_keyword(Array) #1 /var/www/xxxxxx/includes/functions-plugins.php(191): yourls_apply_filter('pre_get_keyword', Array) #2 /var/www/xxxxxx/includes/functions.php(459): yourls_do_action('pre_get_keyword', 'mastering-colla...', true) #3 /var/www/xxxxxx/includes/functions.php(494): yourls_get_keyword_infos('mastering-colla...') #4 /var/www/xxxxxx/includes/functions.php(516): yourls_get_keyword_info('mastering-colla...', 'url', false) #5 /var/www/xxxxxx/includes/functions-html.php(483): yourls_get_keyword_longurl('mastering-colla...') #6 /var/www/xxxxxx/admin/admin-ajax.php(25): yourls_table_edit_row('mastering-colla...') #7 {main}

@tipichris
Copy link
Owner

I still use an older version or Yourls, and of PHP, so I won't be able to test this until I have time to upgrade everything. But it looks as if you will need to change this line in yapchache/plugin.php

$ydb->infos[$keyword] = apc_fetch(yapc_get_keyword_key($keyword));

to

$ydb->set_infos($keyword, apc_fetch(yapc_get_keyword_key($keyword)));    

I don't think this will solve all your problems though. At the least, you'll have to look at similar issues around lines 95 and 96

$ydb->option = apc_fetch($key); 
$ydb->installed = apc_fetch(YAPC_YOURLS_INSTALLED); 

They'll need changing to use $ydb->set_option() and $ydb->set_installed() instead.

@tipichris
Copy link
Owner

Mmm, actually, the $ydb->option bit is going to be more complicated, as we're trying to set an entire array here. Probably need to cycle through it.

@cjstone
Copy link
Author

cjstone commented Mar 5, 2019

Thanks for taking a look at this Chris. I'm happy to test anything further that might help!

@tipichris
Copy link
Owner

OK. I built YAPCache against 1.7.1. It necessarily needs quite low level access to the database and there have been some important changes to the all powerful $ydb object since 1.7.1. Several properties that YAPCache accesses directly are now protected and must be accessed via methods. Methods that didn't exist in 1.7.1, so I can't actually make the changes until I can upgrade. But if you fancy poking about in the code I think what you'll have to do is this (get the latest commit from GitHub first):

Around line 138 change

$ydb->infos[$keyword] = apc_fetch(yapc_get_keyword_key($keyword));

to

$ydb->set_infos($keyword, apc_fetch(yapc_get_keyword_key($keyword)));    

Around line 95 change

            $ydb->option = apc_fetch($key);
            $ydb->installed = apc_fetch(YAPC_YOURLS_INSTALLED);

to

            $options = apc_fetch($key);
            foreach ($options as $name => $value) {
               $this->ydb->set_option($name, $value);
            }
            $ydb->set_installed(apc_fetch(YAPC_YOURLS_INSTALLED));

Let me know how you get on. And if you can't face hacking the code, at least the notes are here for me when I get around to it :)

@tipichris tipichris added the bug label Mar 5, 2019
@tipichris
Copy link
Owner

And as a 'note to self'... I need to look at all the $ydb->query() calls and change them. There are specific methods for beginTransaction() and commit(), and perform() or fetchAffected() should work elsewhere.

@cjstone
Copy link
Author

cjstone commented Mar 5, 2019

Thanks, Chris. Those changes allowed me to use the plugin and edit and delete URLs properly. I do notice that the speed increase from using the cache is not as great as it was before, fwiw.

Thanks again,

--Chris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants