Skip to content

Instantly share code, notes, and snippets.

View nick-hoang's full-sized avatar

Nick Hoàng nick-hoang

  • Code Brewery
  • Hanoi, Vietnam
View GitHub Profile
--Delete old nodes (keep recent 15 days) from Trash, Umbraco 7.7.6
--deletes in Document
--at this point all associated media files are deleted
delete from umbracoDomains where id in (select id from umbracoNode where trashed = 1 and createDate < DATEADD(d, -15, getdate()));
delete from cmsDocument where nodeId in (select id from umbracoNode where trashed = 1 and createDate < DATEADD(d, -15, getdate()));
--deletes in Content
delete from cmsPropertyData where contentNodeId in (select id from umbracoNode where trashed = 1 and createDate < DATEADD(d, -15, getdate()));
delete from cmsPreviewXml where nodeId in (select id from umbracoNode where trashed = 1 and createDate < DATEADD(d, -15, getdate()));
@nick-hoang
nick-hoang / Umbraco.MovePublishedContent.cs
Last active October 31, 2018 06:34
Umbraco - move published content without raising events
public class Mover {
public void PerformMovePublishedContent(IContent content, int parentId, int userId = 0)
{
if(content.ParentId == parentId)
{
return;
}
var contentService = ApplicationContext.Current.Services.ContentService;
if (parentId == Constants.System.Root)
{
@nick-hoang
nick-hoang / CustomLayoutController.js
Last active October 31, 2018 14:42
Umbraco 7 custom layout sample, reuse the default List layout
(function () {
"use strict";
function customLayoutController($scope, listViewHelper, $location, mediaHelper, mediaTypeHelper, assetsService) {
/*
* $scope.items = [
* {
* properties: [
* {
@nick-hoang
nick-hoang / remove-all-umbraco-7-tables.sql
Created February 21, 2020 11:56
Remove all Umbraco 7 tables
use umbraco_db_name
Drop table schema.cmsPreviewXml
Drop table schema.cmsContentVersion
Drop table schema.cmsContentXml
Drop table schema.cmsDocument
Drop table schema.cmsMedia
Drop table schema.cmsMember2MemberGroup
Drop table schema.cmsMember
Drop table schema.cmsTagRelationship
@nick-hoang
nick-hoang / umbracoSettings.config
Created May 6, 2020 16:36
Umbraco settings to remove vietnamese chars from Umbraco urls
<?xml version="1.0" encoding="utf-8"?>
<settings>
<!--
umbracoSettings.config configuration documentation can be found here:
https://our.umbraco.com/documentation/using-umbraco/config-files/umbracoSettings/
Many of the optional settings are not explicitly listed here
but can be found in the online documentation.
-->
@nick-hoang
nick-hoang / Umbraco-7-create-new-content-type.cs
Created May 7, 2020 00:20
Umbraco 7: create new content type
var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
const string contentTypeAlias = "spacerSection";
var section = contentTypeService.GetContentType(contentTypeAlias);
if(section == null)
{
var abstractSection = contentTypeService.GetContentType("abstractSectionTheme");
section = new ContentType(-1)
{
Key = Guid.NewGuid(),
@nick-hoang
nick-hoang / selenium-get-youtube-videos-paging.cs
Last active June 29, 2020 05:42
Use selenium to get the paging token, do post to youtube and parse the video list from response
class Program
{
static void Main(string[] args)
{
using (var driver = new FirefoxDriver())
{
driver.Url = "https://www.youtube.com/results?search_query=m%E1%BB%B9+t%C3%A2m";
var wait = new WebDriverWait(driver, timeout: TimeSpan.FromSeconds(30))
{
PollingInterval = TimeSpan.FromSeconds(5),
@nick-hoang
nick-hoang / Merchello_Notification_Layout.cshtml
Last active July 30, 2020 09:17
Merchello - Order confirmation notification
@{
Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html data-editor-version="2" class="sg-campaigns" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<!--[if !mso]><!-->
@nick-hoang
nick-hoang / IContentExtensions.cs
Created March 23, 2021 17:07
Umbraco v8: Helpful methods to query children of an IContent
public static class IContentExtensions {
public static bool HasChildren(this IContent content)
{
return Umbraco.Core.Composing.Current.Services.ContentService.HasChildren(content.Id);
}
public static int CountChildren(this IContent content, string childDocType = null)
{
return Umbraco.Core.Composing.Current.Services.ContentService.CountChildren(content.Id, childDocType);
}