bedezign / yii2-audit

Yii2 Audit records and displays web/cli requests, database changes, php/js errors and associated data.
https://bedezign.github.io/yii2-audit/
Other
193 stars 112 forks source link

Request details not present in Entry view in Yii 2.0.14 #238

Closed ashaduri closed 5 years ago

ashaduri commented 6 years ago

Hi, On screenshots of yii2-audit I see request details like GET data when viewing entries. For some reason, I cannot get any of that, see the screenshots. I have latest everything (just did "composer upgrade").

I do get these details in yii2 debug page, but I don't see them anywhere in audit's database tables.

Also note that I get some php notices originating from AuditEntry.php (see the screenshot).

audit-1 audit-2 audit-3

Thanks!

Blizzke commented 6 years ago

The warning is actually the piece of code that is writing all panel data to the database (and fails at it). Somehow there is an unexpected array that wasn't serialised.

Is there any way you can get us whatever it is trying to write to the database?

If you have a debugger, you can set a breakpoint in /src/models/AuditEntry.php on line 127 and get us the values of $columns, $rows and $params.

If you don't have a debugger perhaps you can temporarily modify that file and do a var_export(<variable>, true) to a file of those same variables.

Make sure to remove any sensitive information if you're adding them here.

ashaduri commented 6 years ago

Here you are: dump of variables

ashaduri commented 6 years ago

I think I got rid of the problem:

This code puts an array as a value into $params (AuditEntry.php line 126) : $params[$param] = [Helper::serialize($data, $compact), \PDO::PARAM_LOB];

bindValues() expects a different format, namely a simple type of an instance of PdoValue, like this: $params[$param] = new PdoValue(Helper::serialize($data, $compact), \PDO::PARAM_LOB);

Unable to handle this array as parameter, bindValues() just passes it along, with the array ending up in strtr()'s second parameter (as value in array of its second parameter).

With the above code change I no longer get the NOTICE, and the Entry page shows all the information I need.

Blizzke commented 6 years ago

I'll look into it but that code has been in there pretty much since the start and we have 25k+ downloads. Must be a recent change in Yii. What version are you using?

ashaduri commented 6 years ago

This is my "composer show":

2amigos/yii2-chartjs-widget 2.1.2 ChartJs widget for Yii2. amnah/yii2-user 5.0.8 Yii 2 user authentication module bedezign/yii2-audit 1.1.1 Yii2 Audit records and displays web/cli requests, d... behat/gherkin v4.5.1 Gherkin DSL parser for PHP 5.3 bower-asset/bootstrap v3.3.7 The most popular front-end framework for developing... bower-asset/chartjs v2.7.1 Simple HTML5 charts using the canvas element. bower-asset/inputmask 3.3.11 Inputmask is a javascript library which creates an ... bower-asset/jquery 3.2.1
bower-asset/jquery-ui 1.12.1
bower-asset/punycode v1.3.2
bower-asset/typeahead.js v0.11.1 bower-asset/yii2-pjax 2.0.7.1 cebe/markdown 1.1.2 A super fast, highly extensible markdown parser for... codeception/base 2.4.0 BDD-style testing framework codeception/phpunit-wrapper 7.0.2 PHPUnit classes used by Codeception codeception/specify 0.4.6 BDD code blocks for PHPUnit and Codeception codeception/stub 1.0.2 Flexible Stub wrapper for PHPUnit's Mock Builder codeception/verify 0.3.3 BDD assertion library for PHPUnit codemix/yii2-configloader 0.9.1 Build configuration arrays from config files and en... doctrine/instantiator 1.1.0 A small, lightweight utility to instantiate objects... ezyang/htmlpurifier v4.10.0 Standards compliant HTML filter written in PHP fzaninotto/faker v1.7.1 Faker is a PHP library that generates fake data for... guzzlehttp/psr7 1.4.2 PSR-7 message implementation that also provides com... myclabs/deep-copy 1.7.0 Create deep copies (clones) of your objects phar-io/manifest 1.0.1 Component for reading phar.io manifest information ... phar-io/version 1.0.1 Library for handling version information and constr... phpdocumentor/reflection-common 1.0.1 Common reflection classes used by phpdocumentor to ... phpdocumentor/reflection-docblock 4.3.0 With this component, a library can provide support ... phpdocumentor/type-resolver 0.4.0
phpspec/php-diff v1.1.0 A comprehensive library for generating differences ... phpspec/prophecy 1.7.5 Highly opinionated mocking framework for PHP 5.3+ phpunit/php-code-coverage 6.0.1 Library that provides collection, processing, and r... phpunit/php-file-iterator 1.4.5 FilterIterator implementation that filters files ba... phpunit/php-text-template 1.2.1 Simple template engine. phpunit/php-timer 2.0.0 Utility class for timing phpunit/php-token-stream 3.0.0 Wrapper around PHP's tokenizer extension. phpunit/phpunit 7.0.2 The PHP Unit Testing framework. phpunit/phpunit-mock-objects 6.0.1 Mock Object library for PHPUnit psr/http-message 1.0.1 Common interface for HTTP messages sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or method a line of code be... sebastian/comparator 2.1.3 Provides the functionality to compare PHP values fo... sebastian/diff 3.0.0 Diff implementation sebastian/environment 3.1.0 Provides functionality to handle HHVM/PHP environments sebastian/exporter 3.1.0 Provides the functionality to export PHP variables ... sebastian/global-state 2.0.0 Snapshotting of global state sebastian/object-enumerator 3.0.3 Traverses array structures and object graphs to enu... sebastian/object-reflector 1.1.1 Allows reflection of object attributes, including i... sebastian/recursion-context 3.0.0 Provides functionality to recursively process PHP v... sebastian/resource-operations 1.0.0 Provides a list of PHP built-in functions that oper... sebastian/version 2.0.1 Library that helps with managing the version number... swiftmailer/swiftmailer v5.4.9 Swiftmailer, free feature-rich PHP mailer symfony/browser-kit v4.0.4 Symfony BrowserKit Component symfony/console v4.0.4 Symfony Console Component symfony/css-selector v4.0.4 Symfony CssSelector Component symfony/dom-crawler v4.0.4 Symfony DomCrawler Component symfony/event-dispatcher v4.0.4 Symfony EventDispatcher Component symfony/finder v4.0.4 Symfony Finder Component symfony/polyfill-mbstring v1.7.0 Symfony polyfill for the Mbstring extension symfony/yaml v4.0.4 Symfony Yaml Component theseer/tokenizer 1.1.0 A small library for converting tokenized PHP source... vlucas/phpdotenv v1.0.9 Loads environment variables from .env to getenv(... webmozart/assert 1.3.0 Assertions to validate method input/output with nic... yiisoft/yii2 2.0.14.1 Yii PHP Framework Version 2 yiisoft/yii2-authclient 2.1.5 External authentication via OAuth and OpenID for th... yiisoft/yii2-bootstrap 2.0.8 The Twitter Bootstrap extension for the Yii framework yiisoft/yii2-composer 2.0.5 The composer plugin for Yii extension installer yiisoft/yii2-debug 2.0.13 The debugger extension for the Yii framework yiisoft/yii2-faker 2.0.4 Fixture generator. The Faker integration for the Yi... yiisoft/yii2-gii 2.0.6 The Gii extension for the Yii framework yiisoft/yii2-httpclient 2.0.6 HTTP client extension for the Yii framework yiisoft/yii2-jui 2.0.7 The Jquery UI extension for the Yii framework yiisoft/yii2-swiftmailer 2.0.7 The SwiftMailer integration for the Yii framework

This is the bindValues() function:

public function bindValues($values)
{
    if (empty($values)) {
        return $this;
    }

    $schema = $this->db->getSchema();
    foreach ($values as $name => $value) {
        if ($value instanceof PdoValue) {
            $this->_pendingParams[$name] = [$value->getValue(), $value->getType()];
            $this->params[$name] = $value->getValue();
        } else {
            $type = $schema->getPdoType($value);
            $this->_pendingParams[$name] = [$value, $type];
            $this->params[$name] = $value;
        }
    }

    return $this;
}

As you see, it directly puts the $value into $this->params array since it is not PdoValue.

Nash-x9 commented 6 years ago

I've been in the same situation.

Blizzke commented 6 years ago

Yes, like I said, it is for your version (2.0.14). It isn't for all earlier versions. 2.0.13 still uses arrays. Non backwards compatible changes should take a bigger version bump, really not cool.

It's actually PR 15348 that broke this. This PR changed the using PdoValue instead of arrays.

The actual problem is that it works correctly for all versions of Yii2, except for 2.0.14 and beyond. I'll see if we can work around this somehow.

Blizzke commented 6 years ago

A new issue was created for this @ Yii2 to allow for a grace period in this specific case. I'll try to release a new version this weekend as well that can deal with the new PdoValue so that this won't become an issue again in the future.

ashaduri commented 6 years ago

Thank you for such prompt response!

SilverFire commented 6 years ago

Fixed in Yii and will be included in 2.0.14.2 patch release

Blizzke commented 6 years ago

Thanks for that. We'll make sure to update audit so that it's ready for 2.1 :)

yiiness commented 4 years ago

me solved this by change datatype of field audit_data.data from blob to mediumblob