Magento CSV Import Images Missing - mysql

I edited my products by exporting them with the Import/Export Tool in magento, after I imported them I got faced with There was a problem with reindexing process, which I finally fixed.
But now all my images are missing and not displaying in the front end, can someone help me fix this issue?
/1/_/1_7_138.jpg is the format that the CSV images locations are
I also tried moving the images in media/category/product to media/import but still not displaying correctly
I also tried editing file permissions from 755 to 77 in the media folder but still nothing
I also ran this in the corresponding SQL database
INSERT INTO catalog_product_entity_media_gallery (attribute_id, entity_id, `value`)
SELECT ga.attribute_id, v.entity_id, v.value
FROM catalog_product_entity_varchar v
INNER JOIN eav_entity_type et ON et.entity_type_code=\'catalog_product\'
INNER JOIN eav_attribute va ON va.entity_type_id=et.entity_type_id AND
va.frontend_input=\'media_image\' AND va.attribute_id=v.attribute_id
INNER JOIN eav_attribute ga ON va.entity_type_id=et.entity_type_id AND
ga.attribute_code=\'media_gallery\'
LEFT JOIN catalog_product_entity_media_gallery g ON g.entity_id=v.entity_id AND
g.value=v.value
WHERE v.value<>\'no_selection\' AND v.value<>\'\' AND g.value IS NULL;
and got the following error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '\'catalog_product\' INNER JOIN
eav_attribute va ON va.entity_ty

Not sure if you're having the same problem that I did, but when I re-imported products my images broke but the image was still associated with the product, just not set as the base, small, thumbnail, etc
I did something like
update catalog_product_entity_varchar AS v inner join catalog_product_entity_media_gallery AS g on v.entity_id = g.entity_id set v.value = g.value where (v.attribute_id = '85' or v.attribute_id = '86' or v.attribute_id = '87');
in my database to reassign them all.

Check following in
data base table catalog_product_entity_media_gallery is there an entry for image you are looking for.
something like 1 703 17 /1/_/1_7_138.jpg
Then go to media/catalog/product/1/_/ and check if this image file exists.
Additional flush your cache and check.

When using Import/Export, the folder structure in your media/import folder has to be the same as specified in your csv file. So if a media filename is specified as "/1/_/1_7_138.jpg" in your CSV, there must exist a file "/media/import/1/_/1_7_138.jpg" in your Magento root. Otherwise Import/Export won't find the media file.
The easiest solution would be, to not define a folder structure in your csv and to put all media files, that should be imported, directly in media/import/. So in your case:
CSV entry (e.g. in column 'thumbnail'): 1_7_138.jpg
File: /media/import/1_7_138.jpg
Unfortunately, Magento is not capable of importing its own exports! So an exported CSV has to be modified, to be importable in another Magento installation.

Not sure if you're still having issues, but to help with the INSERT query you listed, it's not working because the single quotes are escaped. I'm guessing you found this query in a post somewhere and when the query was posted, the single quotes were escaped with "\'".
If you change all of the \' to just single quotes like this:
INSERT INTO ......
INNER JOIN eav_entity_type et ON et.entity_type_code='catalog_product' <-- is where I changed the \' to just a single '. You'll need to do that with the entire query.
The query should then work. I also suggest as good practice, that you first run the select without the insert command to make sure it gives back good results before running an insert command blindly.

Related

OPENQUERY SQL Server MYSQL UPDATE

I have to work on a linked server. My goal: Update an entire table in mysql server(version:8.0.21) via OPENQUERY in SQL Server(version 13.0.1742.0). I tried this but it generates an error Row cannot be located for updating. Some values may have been changed since it was last read and this one The rowset was using optimistic concurrency and the value of a column has been changed after the containing row was last fetched or resynchronized.
update linkedTable
set
linkedTable.id_parent=unlinkedTable.IdCat1,
linkedTable.code=unlinkedTable.CodeFamilleFAT,
linkedTable.niveau=unlinkedTable.NiveauCategorieFAT,
linkedTable.langue=unlinkedTable.CodeLangueFAT,
linkedTable.nom=unlinkedTable.LibelleCommercialFAT,
linkedTable.descriptionA=unlinkedTable.DescriptifCom1FAT,
linkedTable.vignette=null,
linkedTable.id_categorie=unlinkedTable.id
from openquery(NAMELINKEDSERVER, 'select id_categorie, id_parent, code, niveau, langue, nom, description as descriptionA, vignette from DatabaseMySQL.Table') as linkedTable
inner join DatabaseSQLserver.dbo.Table as unlinkedTable on unlinkedTable.Id = linkedTable.id_categorie
Then I tried this:
update linkedTable
set
linkedTable.id_parent=unlinkedTable.IdCat1,
linkedTable.code=unlinkedTable.CodeFamilleFAT,
linkedTable.niveau=unlinkedTable.NiveauCategorieFAT,
linkedTable.langue=unlinkedTable.CodeLangueFAT,
linkedTable.nom=unlinkedTable.LibelleCommercialFAT,
linkedTable.descriptionA=unlinkedTable.DescriptifCom1FAT,
linkedTable.vignette=null,
linkedTable.id_categorie=unlinkedTable.id
from openquery(NAMELINKEDSERVER, 'select id_categorie, id_parent, code, niveau, langue, nom, description as descriptionA, vignette from DatabaseMySQL.Table') as linkedTable
inner join DatabaseSQLserver.dbo.Table as unlinkedTable on unlinkedTable.Id = linkedTable.id_categorie
where linkedTable.id_categorie = 1
This work but only one row is updated. So I wrote a stored procedure to update each line but it took too much time.
Can someone explain why my first query didn't work (question1) and how I can reduce the time of my stored procedure (question2)?
I use while loop (count the number of id and update each id).
Thank you in advance.
Kind Regards.
I resolve the problem by checking some option on ODBC Driver in MySQL and reading some forum. I check this box.
enter image description here
This option allows to avoid the errors quoted previously. With this option, i can update multiple values without error on join or other request. Thank you Solarflare and "Another guy" (i lost the name) for correcting me (EDIT A POST). Have nice day both.

How can I get the actual files of a node in drupal 7 with SQL query?

I have to get datas from a drupal 7 database, but without the drupal environment, so I can't use the default drupal classes to get it, only SQL codes.
I want to get files of a node, and I wrote this code:
SELECT
tny_t.uri as tny,
tny_t.filename as tny_name,
FROM ".$type."
LEFT JOIN dr_node
ON dr_node.nid= ".$type.".entity_id
LEFT JOIN dr_field_revision_field_teljes_tm_nynyilatkozat
ON dr_field_revision_field_teljes_tm_nynyilatkozat.entity_id=".$type.".entity_id
LEFT JOIN dr_file_managed as tny_t
ON tny_t.fid= dr_field_revision_field_teljes_tm_nynyilatkozat.field_teljes_tm_nynyilatkozat_fid
WHERE dr_node.nid = ".$nid."
It gives me files, but not always the good ones, because in time the older files was replaced to anothers. I think this gives me the older files.
In your case you must use "file_usage" table who track where a file is used.
File usage schema :
So you can use this request to see all files related to specific node :
'SELECT * FROM file_usage fu
LEFT JOIN file_managed fm ON fu.fid = fm.fid
WHERE fu.type = "node"
AND fu.id ='. $nid

CodeIgniter fails Join Operation

I need to use a join operation. This is my code:
$this->db->from('d');
$this->db->where('id',$v);
$this->db->join('p', 'p.id = d.id');
$deal=$this->db->get();
The exception is:
Server returned HTTP response code: 500
The table is:
p(id,home) and d(id, p.id(this value is from p table),school);
What's wrong?
in your query
$this->db->from('d');
$this->db->where('id',$v);
$this->db->join('p', 'p.id = d.id');
$deal=$this->db->get();
where caluse is ambigeous, you have to put it like this
$this->db->where('d.id',$v);
also try
$this->db->join('p', 'p.id = d.id', 'inner' or 'left');
don't put both just put either inner or left in the join query,hopefully this will solve your problem and also make sure p, d are not synonyms they are actuall name of tables which exists in DB with same p, d names and have valid columns.
You have to try and check a few things in here:
1) Whether your database.php file contains the proper credentials. Look for any silly syntax errors as well.
2) Whether you are loading the database class?
3) Some times if you have installed the php package, the mysql driver would not have got installed. check whether you have installed mysql dirver php5-mysqlnd?

How do I set the scope of this MySQL UPDATE operation?

Standard disclaimer: I'm a total know-nothing when it comes to MySQL. The way I'm trying to do things is almost certainly not clever, and I'm open to suggestions for improvement.
I have two databases: wordpress and wordpress3. wordpress3 is a copy of wordpress, converted to UTF-8. In the process of conversion, however, mis-encoded characters caused data loss.
My Goal:
Locate all entries in wordpress.wp_options where the option_value when encoded as UTF-8 is not the same as when encoded as ASCII.
For each entry described by #1 above, update the corresponding entries in wordpress3.wp_options with the data from wordpress, converted to UTF-8.
I'm checking and replacing the option_values column of wp_options right now as a proof of concept. Once I get it working, I want to rejigger the thing so that it does this for all columns in all tables in the database... but that's getting ahead of myself.
My Script:
update wordpress3.wp_options wp3
SET wp3.option_value = (SELECT
CONVERT(wp.option_value using UTF8) from wordpress.wp_options wp
WHERE convert(wp.option_value using ascii) != convert(wp.option_value using utf8)
AND wp.option_id = wp3.option_id)
WHERE [?]
My Issue:
I don't know how to write the WHERE statement for the UPDATE command (hence the [?]). With nothing in that WHERE statement, my script will match and update seven rows the way I want them updated... but then wp3.option_value will be set to NULL for everything that doesn't match the subquery.
I can define the WHERE explicitly, by using option_names for options I know need to be replaced, like so:
WHERE wp3.option_name = 'shortcoder_data';
...but that's slow and clunky.
Thanks!
I used INNER JOIN to join the two tables (wordpress.wp_options wp and wordpress3.wp_options wp3) and select only the entries where wp.option_id and wp3.option_id were the same, but convert(wp.option_value using ascii) and convert(wp.option_value using utf8) were different:
UPDATE wordpress3.wp_options wp3
INNER JOIN wordpress.wp_options wp ON (wp.option_id = wp3.option_id
AND convert(wp.option_value using utf8) != convert(wp.option_value using ascii))
SET wp3.option_value = convert(wp.option_value using utf8);
This seems to have done the trick.

Exporting phpmyadmin query as csv - problems (not a duplicate)

Before anyone says this is a duplicate, I havent found this case anywhere.
I make my query (a joined query with 4 tables) and then hit EXPORT, but it exports just the table and not the query with the combined info and not just the fields I asked for but ALL the fields of the first table in the query. So basically, the query is ignored at the export stage.
I have loooked into "INTO OUTFILE" however, I do not have the right access to access the file after it is created.
I wonder if "INTO OUTFILE" can save files elsewhere? (remotely, I mean)
I wonder if the amount of results (6200( is straining the server?
My code :
SELECT pname, concat(afname, ' ', alname) as artistname, pubname, pwide, phigh, concat(pubcode,'-',psku) as fullsku, catname, concat('/prints/', pubcode,'-',psku, '.jpg') as imagesource, ptext FROM (prints LEFT JOIN publishers ON (publishers.pubid=prints.ppub) LEFT JOIN artists ON (artistid=partist)) LEFT JOIN cats ON (pcat = catid) WHERE psku <> '' AND phigh > 0 ORDER BY pubname,ltrim(alname),ltrim(afname) LIMIT 6200
I have the same problem, when hitting the "export" button at the bottom of my query results, phpmyadmin exports one of the tables, not the query results. I can't figure why. My workaround is to create a new table, adding
CREATE TABLE xxxx AS
before my select query, and then export this new table.
Since I haven't heard anything, I will post my very lame workaround but at least I got what I wanted.
I did a copy/paste into BBEdit and then tidied up the data with a series of find/replaces.
Not ideal and not the quickest solution, but it worked where nothing else would.