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

visit:locate has stopped working #1002

Closed
cnxsoft opened this issue Feb 5, 2021 · 6 comments · Fixed by #1005
Closed

visit:locate has stopped working #1002

cnxsoft opened this issue Feb 5, 2021 · 6 comments · Fixed by #1005
Labels
Milestone

Comments

@cnxsoft
Copy link

cnxsoft commented Feb 5, 2021

How Shlink is set-up

  • Shlink Version: 2.5.2
  • PHP Version: 7.4
  • How do you serve Shlink: Self-hosted nginx
  • Database engine used: MySQL

Summary

Current behavior

When I run the command to update the location it returns an error.

sudo -u www-data php7.4 /srv/www/cnx-software.com/shlink/bin/cli visit:locate
Argument 1 passed to
Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater::buildIsTooOld() must be
of the type int, string given, called in
/srv/www/cnx-software.com/shlink/module/CLI/src/Util/GeolocationDbUpdat
er.php on line 55

Expected behavior

It should update the location without error.

How to reproduce

Run the command above. I have a cron job, and it stopped working after January 31st, 12:00.

Thank you.

@cnxsoft cnxsoft added the bug label Feb 5, 2021
@acelaya
Copy link
Member

acelaya commented Feb 5, 2021

Hey @cnxsoft

Inside your data folder, there should be a GeoLite2-City.mmdb file. Can you attach it to the ticket?

@cnxsoft
Copy link
Author

cnxsoft commented Feb 6, 2021

@acelaya thanks for looking into it.
I can't attach the file since it's too big, but here's a link: https://mega.nz/file/PgJw1L6a#4TWyqUjMMHXw2CkrJfdRCZJ9RIwL1-DK2ZPTjoLWYHI

@acelaya
Copy link
Member

acelaya commented Feb 6, 2021

I'm not being able to reproduce the issue.

Using your file (and others I have tried) the buildEpoch param comes as an integer, and therefore, it doesn't fail.

image

Can you try opening the file module/CLI/src/Util/GeolocationDbUpdater.php, look for these lines:

$meta = $this->geoLiteDbReader->metadata();
if ($this->buildIsTooOld($meta->buildEpoch)) {
    $this->downloadNewDb(true, $mustBeUpdated, $handleProgress);
}

And change it like this?

$meta = $this->geoLiteDbReader->metadata();
+ var_dump($meta);
if ($this->buildIsTooOld($meta->buildEpoch)) {
    $this->downloadNewDb(true, $mustBeUpdated, $handleProgress);
}

Do not add the + sign in front of var_dump($meta);. It's there just so that the line is highlighted.

Then run the command again. It should print something like this, together with the regular command output:

object(MaxMind\Db\Reader\Metadata)#161 (11) {
  ["binaryFormatMajorVersion"]=>
  int(2)
  ["binaryFormatMinorVersion"]=>
  int(0)
  ["buildEpoch"]=>
  int(1611667589)
  ["databaseType"]=>
  string(13) "GeoLite2-City"
  ["description"]=>
  array(1) {
    ["en"]=>
    string(22) "GeoLite2 City database"
  }
  ["ipVersion"]=>
  int(6)
  ["languages"]=>
  array(8) {
    [0]=>
    string(2) "de"
    [1]=>
    string(2) "en"
    [2]=>
    string(2) "es"
    [3]=>
    string(2) "fr"
    [4]=>
    string(2) "ja"
    [5]=>
    string(5) "pt-BR"
    [6]=>
    string(2) "ru"
    [7]=>
    string(5) "zh-CN"
  }
  ["nodeByteSize"]=>
  int(7)
  ["nodeCount"]=>
  int(4150659)
  ["recordSize"]=>
  int(28)
  ["searchTreeSize"]=>
  int(29054613)
}

Then share that output here.

@cnxsoft
Copy link
Author

cnxsoft commented Feb 6, 2021

This is what the output looks like:

object(MaxMind\Db\Reader\Metadata)#161 (11) {
  ["binaryFormatMajorVersion"]=>
  int(2)
  ["binaryFormatMinorVersion"]=>
  int(0)
  ["buildEpoch"]=>
  string(10) "1611667589"
  ["databaseType"]=>
  string(13) "GeoLite2-City"
  ["description"]=>
  array(1) {
    ["en"]=>
    string(22) "GeoLite2 City database"
  }
  ["ipVersion"]=>
  int(6)
  ["languages"]=>
  array(8) {
    [0]=>
    string(2) "de"
    [1]=>
    string(2) "en"
    [2]=>
    string(2) "es"
    [3]=>
    string(2) "fr"
    [4]=>
    string(2) "ja"
    [5]=>
    string(5) "pt-BR"
    [6]=>
    string(2) "ru"
    [7]=>
    string(5) "zh-CN"
  }
  ["nodeByteSize"]=>
  int(7)
  ["nodeCount"]=>
  int(4150659)
  ["recordSize"]=>
  int(28)
  ["searchTreeSize"]=>
  int(29054613)
}


 [ERROR] Argument 1 passed to
         Shlinkio\Shlink\CLI\Util\GeolocationDbUpdater::buildIsTooOld() must be
         of the type int, string given, called in
         /srv/www/cnx-software.com/shlink/module/CLI/src/Util/GeolocationDbUpdat
         er.php on line 56

`

@acelaya
Copy link
Member

acelaya commented Feb 6, 2021

I'm wondering why the GeoLite2 library is parsing the buildEpoch as a string. According to their docs it's an integer.

I'll report it to them.

Thanks for your help 🙂

@acelaya
Copy link
Member

acelaya commented Feb 6, 2021

@cnxsoft since I'm not sure when will we hear from MaxMind, I would suggest this workaround for now:

Add an explicit cast to int in the line I shared above:

- if ($this->buildIsTooOld($meta->buildEpoch)) {
+ if ($this->buildIsTooOld((int) $meta->buildEpoch)) {
    $this->downloadNewDb(true, $mustBeUpdated, $handleProgress);
}

In next version I will include something similar with a bit of validation and error handling, but in your case, this should solve the problem until next release is available.

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