Skip to content

Instantly share code, notes, and snippets.

@shamotj
shamotj / delete_all_products.sql
Created February 9, 2021 08:43
SQL commands to delete all products, product categories and images from Woocommerce.
-- Delete products
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'));
convert original.jpg +profile icm -profile JapanColor2001Coated.icc -profile AdobeRGB1998.icc output.jpg
@shamotj
shamotj / fix_sequences_ownership.sql
Created April 15, 2013 07:08
Usage would typically work like this: Save this to a file, say 'reset.sql' Run the file and save its output in a way that doesn't include the usual headers, then run that output. There are a few limitations to this snippet of code you need to be aware of: 1. It might not work well with multiple schemas 2. It only works on sequences that are owne…
-- This script changes sequences with OWNED BY to the table and column they're
-- referenced from. NB! Sequences that are referenced by multiple tables or columns are ignored.
SELECT 'ALTER SEQUENCE '|| quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
||' OWNED BY '|| quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';'
FROM (
SELECT
n.nspname AS schema_name,
c.relname AS table_name,
a.attname AS column_name,
@shamotj
shamotj / actions.class.php
Created March 26, 2013 15:52
Set HTTP content type in Symfony action.
public funtion executeIndex(sfWebRequest $request)
{
// if we want browser to opt file download
$this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename="file.txt"');
// set content type (text/csv, text/plain ..)
$this->getResponse()->setContentType('text/plain');
// return string immediately, don't try to render template
return $this->renderText($text);
@shamotj
shamotj / delete duplicate record
Created March 25, 2013 11:26
SQL for deleting duplicate records.
DELETE FROM duptest
WHERE name_key NOT IN
(SELECT MAX(dt.name_key)
FROM duptest As dt
GROUP BY dt.first_name, dt.last_name);