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

[athenaeum-flysystem-db] Unable to persist binary data to MariaDB #189

Closed
goldmont opened this issue May 24, 2024 · 9 comments
Closed

[athenaeum-flysystem-db] Unable to persist binary data to MariaDB #189

goldmont opened this issue May 24, 2024 · 9 comments
Assignees

Comments

@goldmont
Copy link

goldmont commented May 24, 2024

Description

Hi,

After a few days I'm still unable to persist my binary data into a MariaDB instance using Laravel. I tried the example in the documentation page and the library seems to save everything correctly into the database except to the blob field which contains always something like Resource id #.... Whatever kind of data I try to save, the result is the same. Could you help me please?

Version & Environment

Laravel: 9
athenaeum-flysystem-db: 6.8.1

Steps to reproduce

  1. Storage::disk('my_disk')->put('example.txt', 'Contents');

image

image

image

image

Expected behaviour

To see the correct data (the text "Contents" in my case)

@goldmont
Copy link
Author

goldmont commented May 24, 2024

Apparently the problem is this line. The latest version of this library (8.3.0) should be affected by this too.

The comment reads:

Database driver should automatically deal with "resource". Alternatively, the resource should be converted to a string, but that COULD increase memory consumption a lot (depending on filesize).

Since the value of the key contents is a resource, then transforming to string the resource results in the error I described above. Instead of calling the resource() method, I'm currently using getContents() and it works like a charm with any kind of data I tested. What are your considerations?

Before:

    protected function prepareContentsRecord(string $path, FileStream $stream, Config $config): array
    {
        // Note: path is not used here, but it is kept to allow eventual customisation / extended
        // versions of this adapter!


        return [
            'hash' => $this->resolveContentHash($stream, $config),


            // Initial reference count. This is ONLY valid when inserting a new
            // record. It must be updated when existing record is updated.
            'reference_count' => 1,


            // Database driver should automatically deal with "resource".
            // Alternatively, the resource should be converted to a string, but
            // that COULD increase memory consumption a lot (depending on filesize).
            'contents' => $stream
                ->positionToStart()
                ->resource()
        ];
    }

After:

    protected function prepareContentsRecord(string $path, FileStream $stream, Config $config): array
    {
        // Note: path is not used here, but it is kept to allow eventual customisation / extended
        // versions of this adapter!


        return [
            'hash' => $this->resolveContentHash($stream, $config),


            // Initial reference count. This is ONLY valid when inserting a new
            // record. It must be updated when existing record is updated.
            'reference_count' => 1,


            // Database driver should automatically deal with "resource".
            // Alternatively, the resource should be converted to a string, but
            // that COULD increase memory consumption a lot (depending on filesize).
            'contents' => $stream
                ->positionToStart()
                ->getContents()
        ];
    }

@aedart
Copy link
Owner

aedart commented May 24, 2024

Hi @goldmont

Thx for reporting this issue. I will try to take a look it as soon as possible,... but this could be a while - got lots of stuff to do this weekend (really sorry). If your work-around / hotfix works for you right now, keep it (You can eventually create a custom extended version of this DatabaseAdapter, and register it in the same way as in the Service Provider).
Hopefully I can take some time for this, early next week (no promises).

In the mean time, my best guess is that either Laravel's database component or PDO is not able to handle a resource (for Maria DB), in the same way that other drivers do (see old issue / pull request for details):

But to verify this, I will have to get MariaDB running and test this myself.

Also, you are using an outdated / unsupported version of Laravel & this package. Even when/if I can reproduce this issue, I cannot guarantee to release a patch for the version 6.x series of this package. If there is any chance that you can upgrade your application, then I recommend it (just in case that this issue is related to PHP's PDO).

@aedart aedart self-assigned this May 24, 2024
@goldmont
Copy link
Author

Hi,

This is exactly what I did. I've extended both the adapter and the provider.

FYI:
However, on MySQL the problem doesn't occur. So there might be some difference on how the driver handles PHP resources on the basis of the database (MySQL or MariaDB).

@aedart
Copy link
Owner

aedart commented May 24, 2024

I fear that this could be more PDO related. If so, then it will become very difficult to resolve. In any case, I will try to reproduce this defect in my current setup (latest version of Laravel, Athenaeum, PHP v8.2,...etc).

@aedart
Copy link
Owner

aedart commented May 28, 2024

Hi @goldmont

I have attempted to reproduce this issue, but sadly without any success. Please see pull request #190 for a few details.
There were two minor bugs, which affected postgresql and mariadb database drivers. Yet, none of them were of this nature.
Note that the tests that I have conducted include League's own Flysystem Adapter Test Utilities.

As I previously mentioned, it can either be your PHP / PDO and or your version of Laravel that are outdated and thus causing this behaviour. If you are able to update your application's dependencies, then you should do so. Otherwise, your own work-around could be the way forward, until you do have the time/resources for upgrading your dependencies and system.

I'm sorry for not being able to help you more than this. Please do feel free to open another issue, if this should arise again - using a newer version of this package, etc.

@goldmont
Copy link
Author

Hi @aedart

Thank you for your time. Could you tell me what PHP version are you using, your MySQL version and so on?

My stack:
MariaDB: 11.3.2
MySQL: 8.0.36
PHP: 8.2.18
Laravel: 9.52.16

@aedart
Copy link
Owner

aedart commented May 29, 2024

Hi @goldmont

I have the following installed:

  • MySQL: N/A (I only installed MariaDB)
  • MariaDB: 15.1, Distrib 10.6.16-MariaDB, for debian-linux-gnu (x86_64)
  • PHP: 8.2.19
  • Laravel: 11.8
  • League/flysystem: 3.28

@aedart
Copy link
Owner

aedart commented May 30, 2024

@goldmont Could you please let me know, if I should close this issue - or keep it open?

@goldmont
Copy link
Author

Hi,

You can close this issue for now. Once upgraded to L11, I'll let you know here 👍🏻 Thank you

@aedart aedart closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants