Skip to content

Instantly share code, notes, and snippets.

View timgaunt's full-sized avatar

Tim Gaunt timgaunt

View GitHub Profile
@timgaunt
timgaunt / Pre v8.sql
Last active March 10, 2021 09:45
Delete umbraco content via SQL
/* Delete Old Document Versions */
Declare @keepOldVersionsCount int, @keepNewerThanDate datetime
Set @keepOldVersionsCount = 0 /* 0 Keeps published and newest only. */
Set @keepNewerThanDate = getdate() /* getDate() or '2013-01-01' */
IF OBJECT_ID('tempdb..#versions') IS NOT NULL DROP TABLE #versions
SELECT VersionID, nodeId, updateDate, newest, published INTO #versions
@timgaunt
timgaunt / Content.sql
Created July 27, 2015 18:46
Export Umbraco data in pivot/crosstab table
DECLARE @cols NVARCHAR(max), @ContentTypeId int
SET @ContentTypeId = 1074
SELECT @cols = STUFF((
SELECT DISTINCT TOP 100 PERCENT
'],['
+ CONVERT(varchar, Name + ' (' + CONVERT(varchar, id) + ')', 255)
FROM
dbo.cmsPropertyType
WHERE
@timgaunt
timgaunt / gist:fab448bf6a889904f02a
Created August 14, 2015 06:47
Delete files after a number of days
forfiles -p "< Path To Folder >" -s -m *.* /D -< Number of days ago > /C "cmd /c del @path"
@timgaunt
timgaunt / Strip extension in Powershell.ps1
Created August 31, 2015 16:31
Strip extension in Powershell
Get-ChildItem "C:\Users\Tim\Desktop\DL\uCommerce\8e0acd5c-f842-49db-933d-cc9e61fcff51\bin" -Filter *.dll.* | `
Foreach-Object{
Rename-Item $_.FullName ([io.fileinfo]$_.FullName).basename
}
@timgaunt
timgaunt / Create Umbraco Database.sql
Created October 28, 2015 16:08
Create an umbraco database -just replace "DATABASENAME" with your database name
USE Master
GO
CREATE DATABASE DATABASENAMECMS
GO
DECLARE @DatabaseName nvarchar(255), @Username nvarchar(255), @Password nvarchar(255), @AddToASPNet bit, @IsUmbracoInstall bit
SET @DatabaseName = 'DATABASENAMECMS' -- NOTE this must also match the CREATE value above and below the "Creating Users" script
SET @Username = 'DATABASENAMEUser'
SET @Password = ''
$ago = 7;
$now = Get-Date;
$limit = $now.AddDays($ago * -1)
$filename = "UmbracoTraceLog.txt.*"
$path = "D:\Websites\"
# Delete files older than the $limit.
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.LastwriteTime -lt $limit -and $_.name -like $filename } | Remove-Item -WhatIf
# Delete any empty directories left behind after deleting the old files.
@timgaunt
timgaunt / EnableDisable.sql
Last active May 9, 2016 23:30
Enable/Disable products without prices
BEGIN TRAN
-- Activate variants
UPDATE uCommerce_Product SET DisplayOnSite = 1, AllowOrdering = 1 where ParentProductId IS NOT NULL
-- Insert the price group prices
INSERT into uCommerce_PriceGroupPrice (ProductId, Price, PriceGroupId)
SELECT p.ProductId, NULL, pg.PriceGroupId
FROM uCommerce_Product p LEFT JOIN uCommerce_PriceGroupPrice pgp ON p.ProductId = pgp.ProductId, uCommerce_PriceGroup pg
WHERE pgp.ProductId IS NULL AND pg.Deleted = 0
@timgaunt
timgaunt / Delete variants without prices.sql
Created May 18, 2016 07:41
Delete the variants (child products) from uCommerce where they don't have a price but the parent is active
BEGIN TRAN
SELECT TOP 100
*
FROM
uCommerce_Product p
LEFT JOIN uCommerce_PriceGroupPrice pgp ON p.ProductId = pgp.ProductId
LEFT JOIN uCommerce_Product pp ON p.ParentProductId = pp.ProductId
WHERE
p.ParentProductId IS NOT NULL
@timgaunt
timgaunt / Common Passwords.txt
Last active May 27, 2016 16:59
List of 500 common passwords to avoid
!QAZ1qaz
!QAZ2wsx
!Qaz2wsx
!QAZxsw2
!QAZzaq1
#EDC4rfv
123qweASD
12qw!@QW
1941.Salembbb.41
1qaz!QAZ
DECLARE
@RowsToDelete INT = 100
, @rows INT = 1
, @batch INT = 1
, @batchestorun INT = 2000
, @message nvarchar(max)
, @keepOldVersionsCount int
, @keepNewerThanDate DATETIME
SET @keepOldVersionsCount = 0 /* 0 Keeps published and newest only. */