Fatal Error When Set CI_DEBUG to False On Production Mode Codeigniter 4 - codeigniter

Why I get this error when set from Config/Boot/production.php CI_DEBUG to false in production mode ? this is the default setting from CI4.
defined('CI_DEBUG') || define('CI_DEBUG', false);
Fatal error: Declaration of CodeIgniter\Log\Logger::emergency($message, array $context = []): bool must be compatible with Psr\Log\LoggerInterface::emergency(Stringable|string $message, array $context = []): void in E:\testing\Source Code\testing_CI_v.4.2.6\system\Log\Logger.php on line 157
Fatal error: Uncaught Error: Class "CodeIgniter\Log\Logger" not found in E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php:391 Stack trace: #0 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(253): CodeIgniter\Config\Services::logger(false) #1 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(194): CodeIgniter\Config\BaseService::__callStatic('logger', Array) #2 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php(388): CodeIgniter\Config\BaseService::getSharedInstance('logger') #3 E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\BaseService.php(253): CodeIgniter\Config\Services::logger(true) #4 E:\testing\Source Code\testing_CI_v.4.2.6\system\Common.php(799): CodeIgniter\Config\BaseService::__callStatic('logger', Array) #5 E:\testing\Source Code\testing_CI_v.4.2.6\system\Debug\Exceptions.php(114): log_message('critical', '{message}\nin {e...', Array) #6 E:\testing\Source Code\testing_CI_v.4.2.6\system\Debug\Exceptions.php(180): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException)) #7 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler() #8 {main} thrown in E:\testing\Source Code\testing_CI_v.4.2.6\system\Config\Services.php on line 391
For Development And Testing Mode run without problem. This error just occur when using routes->resource (RESTFUL API).
It is not clear what error is this. I try to replace the system folder with new one. But the error still exists.
It is said "Uncaught Error: Class "CodeIgniter\Log\Logger" not found" I don't know what is the problem with this and why it is not found.
Now my app just run with set CI_DEBUG to true to prevent the error. But the default is set to false for production.
defined('CI_DEBUG') || define('CI_DEBUG', true);
What is missing in here ? It is so strange that setting the CI_ENVIRONMENT to development or testing worked without a problem. But for production not working. So I decide to turn on the error display in production mode and found the error above.
Seriously help need.

I found the problem in the restful api.
The problem is in the config/filter.php
$routes->resource('ApiManageTips', ['controller' =>'App\Controllers\ApiData\ApiManageTips']); // get, put, create, delete
public $filters = [
'basicauth' => ['before' =>
[
'ApiManageTips/*',
'ApiManageTips',
]
]
];
The Above example is working in the version 4.1.2 but is not working in version 4.2.6
Instead change to :
public $filters = [
'basicauth' => ['before' =>
[
'ApiManageTips/*',
]
];
I don't why it is not working in the CI Version 4.2.6.

Related

Scheduler error on server but not on local host in Laravel

I am testing scheduler and for this, I tested the code on Local machine and it works perfectly, but on live serve, I am facing below error for foreach loop
[2019-11-27 23:00:01] local.ERROR: Invalid argument supplied for foreach() {"exception":"[object] (ErrorException(code: 0): Invalid argument supplied for foreach() at /demon/x/public_html/vendor/symfony/console/Input/ArgvInput.php:261)
[stacktrace]
#0 /demon/x/public_html/vendor/symfony/console/Input/ArgvInput.php(261): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'Invalid argumen...', '/demon/x...', 261, Array)
#1 /demon/x/public_html/vendor/symfony/console/Application.php(983): Symfony\\Component\\Console\\Input\\ArgvInput->getFirstArgument()
#2 /demon/x/public_html/vendor/laravel/framework/src/Illuminate/Console/Application.php(81): Symfony\\Component\\Console\\Application->getCommandName(Object(Symfony\\Component\\Console\\Input\\ArgvInput))
#3 /demon/x/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#4 /demon/x/public_html/artisan(36): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#5 {main}
"}
the function I am trying to call is as below and is in helper function:
function sendNotificationToScheduleMessages() {
// from current time
$from = date('Y-m-d H:i:s', strtotime('now'));
// to the time max
$to = date('Y-m-d H:i:s', strtotime('+1 minutes', strtotime('now')));
//get all pending notification between from and to date timestamp
$notification = ScheduleMessage::whereBetween('trigger_at', [$from, $to])->whereStatusId(4)->get();
if(count($notification) > 0){
Log::info('Data fetched for notification #record - '.$notification->id);
} else {
Log::info('No Notification found form ('.$from.') - to ('.$to.')');
}
}
I've had a similar issue in the past. You haven't shown some of your scheduler info, but I was able to solve this via fixing my cron instruction. So, on your live server, make sure you actually have added Laravel's scheduler to cron.
Something like this:
/usr/local/bin/php register_argc_argv=1 artisan schedule:run >> /dev/null 2>&1
This worked for me, but you may need to play around in this space to match the functionality between your dev machine and the live host.
HTH

Class does not exist vendor/laravel/framework/src/Illuminate/Container/Container.php:790

I'm having problems finding where this error is coming from.
Can anyone shed some light on this error?
I have cleared all cache files and checked the config files for errors.The file is physically there when I use the server's file explorer.
This error occurs on the staging server, running cpanel php7.1. Had no problems while using the local development server.
The stack trace:
[2019-07-06 06:44:49] online.ERROR: Class mollie does not exist {"userId":"70a84900-9fa7-11e9-a421-57dbf5e49d9b","exception":"[object] (ReflectionException(code: -1): Class mollie does not exist at /home/serv/app/vendor/laravel/framework/src/Illuminate/Container/Container.php:790)
[stacktrace]
#0 /home/serv/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(790): ReflectionClass->__construct('mollie')
#1 /home/serv/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(667): Illuminate\\Container\\Container->build('mollie')
#2 /home/serv/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(615): Illuminate\\Container\\Container->resolve('mollie', Array)
#3 /home/serv/app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(767): Illuminate\\Container\\Container->make('mollie', Array)
#4 /home/serv/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(1225): Illuminate\\Foundation\\Application->make('mollie')
#5 /home/serv/app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(175): Illuminate\\Container\\Container->offsetGet('mollie')
#6 /home/serv/app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(144): Illuminate\\Support\\Facades\\Facade::resolveFacadeInstance('mollie')
#7 /home/serv/app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(231): Illuminate\\Support\\Facades\\Facade::getFacadeRoot()
#8 /home/serv/app/app/Http/Controllers/PaymentController.php(62): Illuminate\\Support\\Facades\\Facade::__callStatic('api', Array)
#9 [internal function]: App\\Http\\Controllers\\PaymentController->preparePayment('starter')
the mollie class comes from the official Mollie payment package
https://github.com/mollie/laravel-mollie/blob/master/src/Facades/Mollie.php
I am using it the way the docs describe:
$payment = Mollie::api()->payments()->create([
'amount' => [
'currency' => 'EUR',
'value' => $totalAmount, // You must send the correct number of decimals, thus we enforce the use of strings
],
'description' => $totalCoins,
'webhookUrl' => route('order.hook'),
'redirectUrl' => route('order.success'),
]);
This is the first occurance for Mollie in that method
So in your PaymentController you are referencing a class called mollie which could not be found, physically it is there but you need to import it in your controller in order to be found.
So you might be missing some of this:
use App\mollie; // as an example of import / I don't know the namespace of the file
in your class mollie you forgot to add the namespace

Magento 2 invalid template exception just after installation

I have installed the Magento 2.0 platform on my localhost today. After completing all the setup and installation, when I tried to open the admin panel, it was showing a brown blank screen. When I switched to the developer mode, it is showing an invalid template error for require_js.phtml. The complete error is :
1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'C:/xampp/htdocs/magento_demo/vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js'
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'C:/xampp/htdocs/magento_demo/vendor/magento/module-backend/view/adminhtml/templates/page/js/require_js.phtml' in module: 'Magento_Backend' block's name: 'require.js'
#0 C:\xampp\htdocs\magento_demo\vendor\magento\framework\View\Element\Template.php(301): Magento\Framework\View\Element\Template->fetchView('C:/xampp/htdocs...')
#1 C:\xampp\htdocs\magento_demo\vendor\magento\framework\View\Element\AbstractBlock.php(668): Magento\Framework\View\Element\Template->_toHtml()
#2 C:\xampp\htdocs\magento_demo\vendor\magento\framework\View\Result\Page.php(249): Magento\Framework\View\Element\AbstractBlock->toHtml()
#3 C:\xampp\htdocs\magento_demo\vendor\magento\framework\View\Result\Layout.php(171): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#4 C:\xampp\htdocs\magento_demo\generated\code\Magento\Backend\Model\View\Result\Page\Interceptor.php(193): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#5 C:\xampp\htdocs\magento_demo\vendor\magento\framework\App\Http.php(139): Magento\Backend\Model\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#6 C:\xampp\htdocs\magento_demo\generated\code\Magento\Framework\App\Http\Interceptor.php(24): Magento\Framework\App\Http->launch()
#7 C:\xampp\htdocs\magento_demo\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http\Interceptor->launch()
#8 C:\xampp\htdocs\magento_demo\index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#9 {main}
I have never used Magento before and have no idea what the issue is or how to solve it. Can anyone tell me what to do to solve the issue?
You can execute composer update from project root it will update all missing dependencies.
Other then this it you can flush Magento cache and re deploy static content, follow these steps:
1) php bin/magento cache:flush or (sudo rm -rf <magento-root>/var/generated/* <magento-root>/pub/static/*)
2) php bin/magento setup:static-content:deploy
Now clean you browser cache and reload the page.
Yes, This is the problem with windows. Windows uses "" as separator, the array "directories" contains entries with "/" as separator, so the check will always fail. So you need to fix this by replacing the separator in core file:
Magento\Framework\View\Element\Template\File\Validator
function isPathInDirectories replace below code in isPathInDirectories function
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
How to fix Invalid template file error in Magento2 after version upgrade?
In case of windows, just replace this function isPathInDirectories in vendor/magento/framework/view/element/template/file/validator.php
protected function isPathInDirectories($path, $directories)
{
$realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
if (!is_array($directories)) {
$directories = (array)$directories;
}
foreach ($directories as $directory) {
if (0 === strpos($realPath, $directory)) {
return true;
}
}
return false;
}

php, postgresql and phppgadmin: errors after changes made to files

I was getting deprecated constructor error when I tried installing postgres with xampp. Though I was able to resolve those issues but I am unable to solve the one below. Kindly help to solve this.
Fatal error: Uncaught Error: Call to undefined method ADORecordSet_postgres7::ADORecordSet_postgres64() in C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres7.inc.php:220 Stack trace:
#0 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1055): ADORecordSet_postgres7->__construct(Resource id #19, 2)
#1 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1015): ADOConnection->_Execute('select version(...', false)
#2 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(1427): ADOConnection->Execute('select version(...', false)
#3 C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres64.inc.php(129): ADOConnection->GetOne('select version(...')
#4 C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres64.inc.php(697): ADODB_postgres64->ServerInfo()
#5 C:\xampp\phppgadmin\libraries\adodb\adodb.inc.php(525): ADODB_postgres64->_connect('host='localhost...', ''postgres'', ''password'', ''template1'')
#6 C:\xampp\phppgadmin\classes\database\Connection.php(42): ADOConnection->Connect('localhost:5432:...', 'postgres', ' in C:\xampp\phppgadmin\libraries\adodb\drivers\adodb-postgres7.inc.php on line 220
You should also change the constructor in adodb-postgres7.inc.php by replacing
function ADODB_postgres7()
with
function __construct()

error when using createEntityTables

I get this error when I include
$installer->createEntityTables( $this->getTable('red/red') );
I am using enterprise 1.11
I have also seen alternative to that is type every thing which is really time consuming. Could someone please tell me who to make this function work.
[previous:Exception:private] =>
[xdebug_message] => ( ! ) Mage_Eav_Exception: Can't create table: red_faqs_eavexample in C:\wamp\www\ubt.onlocal.com.au\app\Mage.php on line 549
Call Stack
#TimeMemoryFunctionLocation
10.0003690528{main}( )..\index.php:0
20.00271167384Mage::run( )..\index.php:81
30.01012776112Mage_Core_Model_App->run( )..\Mage.php:640
40.02304545784Mage_Core_Model_App->_initModules( )..\App.php:338
50.46364871080Mage_Core_Model_Resource_Setup::applyAllUpdates( )..\App.php:412
60.528411772936Mage_Core_Model_Resource_Setup->applyUpdates( )..\Setup.php:235
70.528611769664Mage_Core_Model_Resource_Setup->_installResourceDb( )..\Setup.php:327
80.528611769824Mage_Core_Model_Resource_Setup->_modifyResourceDb( )..\Setup.php:421
90.529511778144include( 'C:\wamp\www\ubt.onlocal.com.au\app\code\local\Magelocal\Red\sql\red_setup\install-0.1.0.php' )..\Setup.php:624
100.529711778712Mage_Eav_Model_Entity_Setup->createEntityTables( )..\install-0.1.0.php:6
)
Error in file: "C:\wamp\www\ubt.onlocal.com.au\app\code\local\Magelocal\Red\sql\red_setup\install-0.1.0.php" - Can't create table: red_faqs_eavexample
#0 C:\wamp\www\ubt.onlocal.com.au\app\code\core\Mage\Core\Model\Resource\Setup.php(645): Mage::exception('Mage_Core', 'Error in file: ...')
#1 C:\wamp\www\ubt.onlocal.com.au\app\code\core\Mage\Core\Model\Resource\Setup.php(421): Mage_Core_Model_Resource_Setup->_modifyResourceDb('install', '', '0.1.0')
#2 C:\wamp\www\ubt.onlocal.com.au\app\code\core\Mage\Core\Model\Resource\Setup.php(327): Mage_Core_Model_Resource_Setup->_installResourceDb('0.1.0')
#3 C:\wamp\www\ubt.onlocal.com.au\app\code\core\Mage\Core\Model\Resource\Setup.php(235): Mage_Core_Model_Resource_Setup->applyUpdates()
#4 C:\wamp\www\ubt.onlocal.com.au\app\code\core\Mage\Core\Model\App.php(412): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#5 C:\wamp\www\ubt.onlocal.com.au\app\code\core\Mage\Core\Model\App.php(338): Mage_Core_Model_App->_initModules()
#6 C:\wamp\www\ubt.onlocal.com.au\app\Mage.php(640): Mage_Core_Model_App->run(Array)
#7 C:\wamp\www\ubt.onlocal.com.au\index.php(81): Mage::run('', 'store')
#8 {main}
This is a problem with an error being triggered when it shouldn't be. Long story short, MySQL doesn't support DDL transactions, and in the course of the method DDL routines are being found in the SQL and an error is thrown.
The easy answer is to comment out this line:
lib/Varien/Db/Adapter/PDO/Mysql.php
protected function _checkDdlTransaction($sql)
{
if (is_string($sql) && $this->getTransactionLevel() > 0) {
$startSql = strtolower(substr(ltrim($sql), 0, 3));
if (in_array($startSql, $this->_ddlRoutines)) {
// comment this out: trigger_error(Varien_Db_Adapter_Interface::ERROR_DDL_MESSAGE, E_USER_ERROR);
}
}
}
Doing so allows your module to install. Obviously hacking a core file is a terrible idea. You should extend the method or allow the SQL to run, and then translate the generated SQL into the Magento MySQL API, as seen in core sql setup scripts. The latter is a major pain.. the better idea would be to extend the method.
More here on background information and troubleshooting.

Resources