klimeryk / recalendar

ReCalendar - highly customizable calendar for ReMarkable tablets
GNU General Public License v3.0
197 stars 23 forks source link

php generate.php throws "HP Fatal error: Uncaught Error: Class 'ReCalendar\Config' not found in /home/oren/p/recalendar/config.php:5" #1

Closed oren closed 3 years ago

oren commented 3 years ago
git clone https://github.com/klimeryk/recalendar
cd recalendar
composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - mpdf/mpdf is locked to version v8.0.11 and an update of this package was not requested.
    - mpdf/mpdf v8.0.11 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension.

To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php/7.4/cli/php.ini
    - /etc/php/7.4/cli/conf.d/10-opcache.ini
    - /etc/php/7.4/cli/conf.d/10-pdo.ini
    - /etc/php/7.4/cli/conf.d/20-calendar.ini
    - /etc/php/7.4/cli/conf.d/20-ctype.ini
    - /etc/php/7.4/cli/conf.d/20-exif.ini
    - /etc/php/7.4/cli/conf.d/20-ffi.ini
    - /etc/php/7.4/cli/conf.d/20-fileinfo.ini
    - /etc/php/7.4/cli/conf.d/20-ftp.ini
    - /etc/php/7.4/cli/conf.d/20-gettext.ini
    - /etc/php/7.4/cli/conf.d/20-iconv.ini
    - /etc/php/7.4/cli/conf.d/20-json.ini
    - /etc/php/7.4/cli/conf.d/20-phar.ini
    - /etc/php/7.4/cli/conf.d/20-posix.ini
    - /etc/php/7.4/cli/conf.d/20-readline.ini
    - /etc/php/7.4/cli/conf.d/20-shmop.ini
    - /etc/php/7.4/cli/conf.d/20-sockets.ini
    - /etc/php/7.4/cli/conf.d/20-sysvmsg.ini
    - /etc/php/7.4/cli/conf.d/20-sysvsem.ini
    - /etc/php/7.4/cli/conf.d/20-sysvshm.ini
    - /etc/php/7.4/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
~/p/recalendar ls
composer.json  composer.lock  config.php  example  fonts  generate.php  generators  LICENSE  README.md  recalendar.php  SCREENSHOTS.md  style.css
~/p/recalendar php --ini
Configuration File (php.ini) Path: /etc/php/7.4/cli
Loaded Configuration File:         /etc/php/7.4/cli/php.ini
Scan for additional .ini files in: /etc/php/7.4/cli/conf.d
Additional .ini files parsed:      /etc/php/7.4/cli/conf.d/10-opcache.ini,
/etc/php/7.4/cli/conf.d/10-pdo.ini,
/etc/php/7.4/cli/conf.d/20-calendar.ini,
/etc/php/7.4/cli/conf.d/20-ctype.ini,
/etc/php/7.4/cli/conf.d/20-exif.ini,
/etc/php/7.4/cli/conf.d/20-ffi.ini,
/etc/php/7.4/cli/conf.d/20-fileinfo.ini,
/etc/php/7.4/cli/conf.d/20-ftp.ini,
/etc/php/7.4/cli/conf.d/20-gettext.ini,
/etc/php/7.4/cli/conf.d/20-iconv.ini,
/etc/php/7.4/cli/conf.d/20-json.ini,
/etc/php/7.4/cli/conf.d/20-phar.ini,
/etc/php/7.4/cli/conf.d/20-posix.ini,
/etc/php/7.4/cli/conf.d/20-readline.ini,
/etc/php/7.4/cli/conf.d/20-shmop.ini,
/etc/php/7.4/cli/conf.d/20-sockets.ini,
/etc/php/7.4/cli/conf.d/20-sysvmsg.ini,
/etc/php/7.4/cli/conf.d/20-sysvsem.ini,
/etc/php/7.4/cli/conf.d/20-sysvshm.ini,
/etc/php/7.4/cli/conf.d/20-tokenizer.ini

I fix it with composer install --ignore-platform-reqs

i create a config.php

<?php

namespace ReCalendar;

class LocalConfig extends Config {
  protected function get_configuration() : array {
    return array_merge( parent::get_configuration(), [
      self::YEAR => 3000,
      self::SPECIAL_DATES => [
        '04-05' => [ 'May The Fourth Be With You' ],
    '24-12' => [ 'Christmas' ],
      ],
      self::WEEKLY_TODOS => [
        'Plan week',
    'Send the weekly email',
      ],
    ] );
  }
}

and i run this command:

php generate.php

PHP Fatal error:  Uncaught Error: Class 'ReCalendar\Config' not found in /home/oren/p/recalendar/config.php:5
Stack trace:
#0 /home/oren/p/recalendar/generate.php(4): require_once()
#1 {main}
  thrown in /home/oren/p/recalendar/config.php on line 5
bennyandresen commented 3 years ago

The documentation is not proper. You need a local config.

You've changed the contents of config.php and thus made the class not exist.

Please reset your git head hard git reset --hard

Then copy the local.config.php from the examples directory to the root directory and generate again.

klimeryk commented 3 years ago

The documentation is not proper. You need a local config.

Sorry about that - I could have sworn I tested this 🤦‍♂️ I've fixed it in https://github.com/klimeryk/recalendar/commit/f24c0066b353f9d405f97b70be23612d50cedd7e

@oren, make sure you pull the newest version using git pull in the folder (or redownload the ZIP archive).

i create a config.php

To make sure we're on the same page: you should not modify config.php directly. Instead, create a new local.config.php (in the same folder). You can copy one from the example folder as a starting point. Hope that helps!

oren commented 3 years ago
git reset --hard
git pull
cp example/local.config.php .
php generate.php

PHP Fatal error:  Uncaught Mpdf\MpdfException: mbstring extension must be loaded in order to run mPDF in /home/oren/p/recalendar/vendor/mpdf/mpdf/src/Mpdf.php:9628
Stack trace:
#0 /home/oren/p/recalendar/vendor/mpdf/mpdf/src/Mpdf.php(1031): Mpdf\Mpdf->_dochecks()
#1 /home/oren/p/recalendar/generate.php(54): Mpdf\Mpdf->__construct()
#2 {main}
  thrown in /home/oren/p/recalendar/vendor/mpdf/mpdf/src/Mpdf.php on line 9628
klimeryk commented 3 years ago

Ah, now it's more clear :) As the message implies - mPDF (the library I'm using to generate the PDFs) requires the mbstring extension to be installed and enabled. I assumed that's default on new installations, but apparently not? I'll add it to the README file (done in https://github.com/klimeryk/recalendar/commit/974df256cc5f449f05b6ade3ebcf3af0dd001879).

You can run php -i and check if you have a mbstring section. This is how it looks like on my system:

mbstring

Multibyte Support => enabled
Multibyte string engine => libmbfl
HTTP input encoding translation => disabled
libmbfl version => 1.3.2

Unfortunately, how to install and enable this extension (and, apparently, also gd) depends on your configuration and operating system. As usual, a quick internet search should give some answers :) Hope this helps!

oren commented 3 years ago

I am on ubuntu 20.10. I had to run sudo apt install php7.4-mbstring

Thanks for the help. You might want to add to the readme this line: cp example/local.config.php. so others can just copy paste from the readme.

klimeryk commented 3 years ago

Thanks for the follow-up and documenting the step needed on Ubuntu - might come in handy for someone else encountering the same issue and searching for it 🙇

You might want to add to the readme this line: cp example/local.config.php. so others can just copy paste from the readme.

Good idea! I've added it in https://github.com/klimeryk/recalendar/commit/43351381fb86dbce83bb855825a934a78b7fb195