$ alias wr=”cd /var/www/html”
Tag Archives: PHP
mysql CSV import
LOAD DATA LOCAL INFILE '/root/Desktop/tablename.csv' INTO TABLE TABLE-NAME ;
magento 2 unable to unserialize value
Open the file \vendor\magento\framework\Serialize\Serializer\json.php and replace the function unserialize() with the below
public function unserialize($string) {
/* Added the following if clause to resolve the issue */
if($this->is_serialized($string)){
$string = $this->serialize($string);
}
$result = json_decode($string, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException('Unable to unserialize value.');
}
return $result;
}
Also add the following function as well
function is_serialized($value, &$result = null) {
// Bit of a give away this one
if (!is_string($value))
{
return false;
}
// Serialized false, return true. unserialize() returns false on an
// invalid string or it could return false if the string is serialized
// false, eliminate that possibility.
if ($value === 'b:0;')
{
$result = false;
return true;
}
$length = strlen($value);
$end = '';
switch ($value[0])
{
case 's':
if ($value[$length - 2] !== '"')
{
return false;
}
case 'b':
case 'i':
case 'd':
// This looks odd but it is quicker than isset()ing
$end .= ';';
case 'a':
case 'O':
$end .= '}';
if ($value[1] !== ':')
{
return false;
}
switch ($value[2])
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
break;
default:
return false;
}
case 'N':
$end .= ';';
if ($value[$length - 1] !== $end[0])
{
return false;
}
break;
default:
return false;
}
if (($result = @unserialize($value)) === false)
{
$result = null;
return false;
}
return true;
}
Magento 2: setup upgrade error “We can’t find the role for the user you wanted”
open the file
vendor/magento/module-authorization/Model/Acl/AclRetriever.php and replaced the below code
if (!$role) {
throw new AuthorizationException(
__('We can\'t find the role for the user you wanted.')
);
}
$allowedResources = $this->getAllowedResourcesByRole($role->getId());
with
if (!$role) {
$allowedResources = array();
}
and revert it on sucess.
Magento 2 merge css js db level
Following are the fields you need to set 0 or 1 in core_config_data table to merge / unmergae css/js files.
dev/js/merge_files - Merge Js
update core_config_data set value=0 where path='dev/js/merge_files';
dev/css/merge_css_files - Merge css
update core_config_data set value=0 where path='dev/css/merge_css_files' limit 20;
Invalid Base URL. Value must be a URL or one of placeholders: {{base_url}}
Make sure that URL ends with a /(slash) .
example : http://phpcodez.com/
Magento 2 Observers
Observers are the particular classes that control the general behavior, performance, or change in the business logic of the store. They are executed whenever a specific event for which they were set to listen is triggered.
To create an observer in Magento 2, you must place your class file under the ModuleRoot/Observer
directory. The observer class file should use Magento\Framework\Event\Observer
and Magento\Framework\Event\ObserverInterface
class and define the executive function.
Magento 2 Events
Events are dispatched by Magento 2 modules whenever specific actions are triggered. When an event dispatches, it passes data to the observer that is configured to watch (or monitor) that event. You can dispatch Magento 2 Events using the Magento\Framework\Event\Manager
class. This class can be obtained through dependency injection by defining the dependency in the constructor method of the class.
To dispatch an event, you have to call the dispatch function of the event manager class, providing the name of the event along with an array of data that you wish to deliver to observers.
Magento 2 Session Factory Does Not Exist
Issue the following command to fix the issue.
php bin/magento setup:static-content:deploy -f php bin/magento setup:di:compile php bin/magento indexer:reindex php bin/magento cache:flush
Magento 2 Default Nginx Configuration
upstream fastcgi_backend {
server unix:/var/run/php-fpm/php-fpm.sock;
}
server {
listen 80;
server_name www.phpcodez.com phpcodez.com;
set $MAGE_ROOT /usr/share/nginx/html/phpcodez;
include /usr/share/nginx/html/phpcodez/nginx.conf.sample;
}