Imagick : generate image from firs page pdf document - imagick

I use this code (CMS used CMSMS)
$obj = $params['item_object'];
$fd = $obj->fielddefs['envoipdf'];
$fd = $fd->GetImagePath(true) . '/' . $fd->value;
$ali = $obj->alias;
$im = new Imagick();
$im->setResolution(72,72);
$im->readImage($fd."[0]");
If I replace
$im->readImage($fd."[0]");
by
$im->readImage($fd);
and put a single page pdf document, no matter the image is well generated.
The returned path is like
https://www.maropclac.com/uploads/gabkio/placa/visuel-exercice-003.pdf
But with a multiple page pdf document and
$im->readImage($fd."[0]");
this returns
Fatal error: Uncaught ImagickException: Imagick::readImage(): HTTP request failed! HTTP/1.1 404 Not Found in /home/tukbix92dqp/testserv/lib/classes/class.usertagoperations.inc.php(305) : eval()'d code:7 Stack trace: #0 /home/tukbix92dqp/testserv/lib/classes/class.usertagoperations.inc.php(305) : eval()'d code(7): Imagick->readImage('https://www.maro...') #1 /home/tukbix92dqp/testserv/lib/classes/class.usertagoperations.inc.php(285): cms_user_tag_slthumb(Array, Object(Smarty_CMS)) #2 /home/tukbix92dqp/testserv/lib/classes/class.Events.php(126): UserTagOperations->CallUserTag('slthumb', Array) #3 /home/tukbix92dqp/testserv/modules/LISE/lib/class.LISEItemOperations.php(232): Events::SendEvent('LISEjourmaro', 'PostItemSave', Array) #4 /home/tukbix92dqp/testserv/modules/LISE/LISE.module.php(631): LISEItemOperations::Save(Object(LISEjourmaro), Object(LISEItem)) #5 /home/tukbix92dqp/testserv/modules/LISE/framework/action.admin_edititem.php(218): LISE->SaveItem(Object(LISEItem)) #6 /home/tukbix92dqp/testserv/modules/LISE/l in /home/tukbix92dqp/testserv/lib/classes/class.usertagoperations.inc.php(305) : eval()'d code on line 7
Perhaps someone can help me....

Related

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

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.

d3.dart 0.2.0 - method not found: '_proxy'

I am starting to use a dart API for d3.js (found here: https://pub.dartlang.org/packages/d3) and I came across a problem, when I tried to create a Axis using TimeScale.
Console:
oSuchMethodError: method not found: '_proxy'
Receiver: Instance of 'TimeScale'
Arguments: []
timeline.dart code
x = new time.TimeScale()
..range([0, width])
..domain([new DateTime(1999, 0, 1), new DateTime(2014, 0, 0)]);
x = new svg.Axis()
..scale(x);
Log:
#0 Object._noSuchMethod (dart:core-patch/object_patch.dart:44)
#1 Object.noSuchMethod (dart:core-patch/object_patch.dart:47)
#2 getProxy (package:d3/src/js/scale.dart:679:31)
#3 Axis.scale (package:d3/src/js/svg.dart:867:16)
#4 Timeline.attached (http://localhost:20080/frontend/dart/components/timeline.dart:29:9)
#5 Application.init.<init_async_body>.<anonymous closure> (http://localhost:20080/frontend/dart/application/application.dart:128:25)
#6 _HashVMBase&MapMixin&&_LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:351)
#7 Application.init.<init_async_body> (http://localhost:20080/frontend/dart/application/application.dart:105:37)
#8 Future.Future.microtask.<anonymous closure> (dart:async/future.dart:144)
#9 _microtaskLoop (dart:async/schedule_microtask.dart:41)
#10 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#11 _ScheduleImmediateHelper._handleMutation (dart:html:49308)
[[class]]: _StackTrace(anonymous function) # VM2334:1
VM2334:1 Uncaught Unhandled exception:
Closure call with mismatched arguments: function '_proxy'
NoSuchMethodError: method not found: '_proxy'
Receiver: Instance of 'TimeScale'
Arguments: []
#0 Application.init.<init_async_body>.<anonymous closure> (http://localhost:20080/frontend/dart/application/application.dart:131:21)
#1 _HashVMBase&MapMixin&&_LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:351)
#2 Application.init.<init_async_body> (http://localhost:20080/frontend/dart/application/application.dart:105:37)
#3 Future.Future.microtask.<anonymous closure> (dart:async/future.dart:144)
#4 _microtaskLoop (dart:async/schedule_microtask.dart:41)
#5 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#6 _ScheduleImmediateHelper._handleMutation (dart:html:49308)(anonymous function) # VM2334:1
d3/src/js/scale.dart - line 679
JsObject getProxy(arg) => arg._proxy;
d3/src/js/svg.dart
scale([scale = undefined]) {
var args = [];
if (scale != undefined) {
//line 867
args.add(sc.getProxy(scale));
}
var retval = _proxy.callMethod('scale', args);
if (scale == undefined) {
return retval; // TODO: wrap in Scale
} else {
return new Axis._(retval);
}
}
Did anyone know what's wrong ?
Thanks
Looking at the package code, you will only be able to give a scale parameter that belong to d3/src/js/scale.dart library.
Using a private member like in arg._proxy will retrieve the _proxy attribute only for arg inside the same library (that's what the prepending _ means : private to its library).
Unfortunately I don't see any simple solution to workaround your issue with the current package sources.

Set product attribute value in magento errors

I'm writing an importer that creates new attribute (which works) and now I want to set different attribute values for different products, without using attribute sets. A method that seems to work for a lot of people seems to be the following:
Mage::getSingleton('catalog/product_action')
->updateAttributes([$id], ['color'=>'red'], self::STORE_ID);
Sadly this errors for me:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'attribute_id' in 'where clause'' in /vagrant/htdocs/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /vagrant/htdocs/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /vagrant/htdocs/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /vagrant/htdocs/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /vagrant/htdocs/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#4 /vagrant/htdocs/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DELETE FROM `ca...', Array)
#5 /vagrant/htdocs/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('DELETE FROM `ca...', Array)
#6 /vagrant/htdocs/lib/Zend/Db/Adapter/Abstract.php(664): Varien_Db_Adapter_Pdo_Mysql->query('DELETE FROM `ca...')
#7 /vagrant/htdocs/app/code/core/Mage/Catalog/Model/Resource/Abstract.p in /vagrant/htdocs/lib/Zend/Db/Statement/Pdo.php on line 235
Is there a better method or am I just doing something wrong?
In order to save attribute values for product, you have to load product object first then set attribute values.. See the example below:
$id = 102; // Your product id
$product = Mage::getModel("catalog/product")->load($id);
$product->setStatus(1);
$product->setColor("red");
$product->save();
As I have learned a very good and performant way is to work with the Resource model:
$product = Mage::getModel('catalog/product');
$product->setId($productId);
$product->setStoreId($storeId);
$product->setColor('red');
// or
// $product->setDataUsingMethod('color', 'red')
$resource = Mage::getResourceModel('catalog/product');
$resource->saveAttribute($product, 'color');

FPDI Fatal error: Uncaught exception 'Exception' with message 'Unable to find object (1, 0)

I'm trying to import a pdf with php class FPDI with this simple code:
require_once("fpdf/fpdf.php");
require_once("fpdi/fpdi.php");
$pdf = new FPDI();
$pdf->setSourceFile('intermedia.pdf');
$tplidx = $pdf->ImportPage(1);
$pdf->AddPage();
$pdf->useTemplate($tplidx,0,0,210);
$pdf->Output();
but I receive the following error:
Warning: explode() [function.explode]: Empty delimiter. in
/var/catalogo/test_pdf/fpdi/pdf_parser.php on line 369
Fatal error: Uncaught exception 'Exception' with message 'Unable to
find object (1, 0) at expected location.' in
/var/catalogo/test_pdf/fpdi/pdf_parser.php:709 Stack trace: #0
/var/catalogo/test_pdf/fpdi/pdf_parser.php(268):
pdf_parser->resolveObject(Array) #1
/var/catalogo/test_pdf/fpdi/pdf_parser.php(208):
pdf_parser->_readRoot() #2
/var/catalogo/test_pdf/fpdi/fpdi_pdf_parser.php(71):
pdf_parser->__construct('/var/catalogo/t...') #3
/var/catalogo/test_pdf/fpdi/fpdi.php(128):
fpdi_pdf_parser->__construct('/var/catalogo/t...') #4
/var/catalogo/test_pdf/fpdi/fpdi.php(108):
FPDI->_getPdfParser('/var/catalogo/t...') #5
/var/catalogo/test_pdf/index.php(5):
FPDI->setSourceFile('intermedia.pdf') #6 {main} thrown in
/var/catalogo/test_pdf/fpdi/pdf_parser.php on line 709
This is the file that should be imported:
http://catalogo.selectaspa.it/test_pdf/intermedia.pdf
Ok, the cross reference of this file is simply corrupted. I just catched the "Warning" on explode for now but at the end you will have to resave the document with e.g. Acrobat to repair it before passing it to FPDI.
You may change pdf_parser.php around line 362 to:
// get Line-Ending
$found = preg_match_all("/(\r\n|\n|\r)/", substr($data, 0, 100), $m); // check the first 100 bytes for line breaks
if ($found === 0) {
throw new Exception('Xref table seems to be corrupted.');
}
Same fix can be used in the separate FPDI PDF-Parser which will allow you to read this document then, too.

Magento model collections - save data

So I'm loading a collection of products using this code:
$magento_time= 'some time string';
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addFieldToFilter(array(
array('attribute'=> 'updated_at', 'gt'=> date('Y-m-d H:i:s', strtotime($magento_time))),
));
$collection->save();
And getting this error in return on save:
Warning: Invalid argument supplied for foreach() in /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 970
#0 /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php(970): mageCoreErrorHandler(2, 'Invalid argumen...', '/var/www/magent...', 970, Array)
#1 /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Abstract.php(925): Mage_Eav_Model_Entity_Abstract->_collectSaveData(Object(Mage_Catalog_Model_Product))
#2 /var/www/magento/app/code/core/Mage/Core/Model/Abstract.php(251): Mage_Eav_Model_Entity_Abstract->save(Object(Mage_Catalog_Model_Product))
#3 /var/www/magento/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(845): Mage_Core_Model_Abstract->save()
#4 /var/www/magento/app/code/local/MyModule/controllers/IndexController.php(16): Mage_Eav_Model_Entity_Collection_Abstract->save()
#5 /var/www/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(376): MyModule_IndexController->sayHelloAction()
#6 /var/www/magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(248): Mage_Core_Controller_Varien_Action->dispatch('sayHello')
#7 /var/www/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(158): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#8 /var/www/magento/app/Mage.php(459): Mage_Core_Controller_Varien_Front->dispatch()
#9 /var/www/magento/index.php(68): Mage::run()
#10 {main}
How do I save products back to the database after they've been loaded into a collection?
Changing the following worked for me:
Manually set the current store:
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
Save each collection independently.
foreach ($collection as $entry) {
$entry->save();
}
EDIT:
Note the Magento API has changed significantly since I first asked this question ~2.5 years ago - this answer may no longer apply.
You do a foreach and save elements one by one.

Resources