Skip to content

Instantly share code, notes, and snippets.

@pedroadaodev
pedroadaodev / umbraco db cleanup.sql
Last active August 11, 2021 09:52 — forked from dampee/umbraco db cleanup.sql
Umbraco Database cleanup. After pulling in an umbraco database from production, you don't need all history or log.
-- Umbraco Clear Old Document Versions To Decrease Database Size And Improve Performance
-- http://borism.net/2008/12/16/fixing-a-large-cmspropertydata-table-in-umbraco/
--DECLARE @createdDate Datetime = DATEADD(m, -1, getdate()) -- If you want to get 2 weeks without maintenance - 40 minutes to run
DECLARE @createdDate Datetime = DATEADD(day, -10, getdate()) -- If you want to get 3/4 weeks without maintenance - 60 minutes to run
--select @createdDate
-- dump logs
-- TRUNCATE TABLE umbracolog -- faster if log table is very big and you don't need anything
DELETE FROM umbracolog WHERE Datestamp < @createdDate
print 'deleted umbracologs'
@pedroadaodev
pedroadaodev / ProductController.cs
Last active April 15, 2021 14:24
UmbracoControllerRedirectTo404Page
public class ProductController : Umbraco.Web.Mvc.RenderMvcController
{
public ActionResult ProductPageTemplate(RenderModel model, string productId)
{
if(productId.IsValidProductInDatabase())
{
// Product is valid
return base.Index(model);
}
else
@pedroadaodev
pedroadaodev / MyNewController.cs
Created June 22, 2018 17:26
UmbracoApiController custom routes
using System.Web.Http;
[RoutePrefix("api/store")]
public class StoreController : Umbraco.Web.WebApi.UmbracoApiController
{
[HttpGet]
[Route("")]
public List<StoreModel> GetAll()
{
return StoreManager.GetAll();
@pedroadaodev
pedroadaodev / FreshdeskTicketCreate.cs
Created March 29, 2018 10:55
FreshDesk create new Ticket
// ADD FOR latest SSL standards
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
// IGNORE SSL certification errors
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
var url = "https://my.freshdesk.com/";
var username = ConfigurationManager.AppSettings["Freshdesk.AppUsername"];
var key = ConfigurationManager.AppSettings["Freshdesk.AppKey"];
HttpClient client = new HttpClient();
@pedroadaodev
pedroadaodev / FacebookShareCountByUrl.cs
Created February 15, 2018 18:54
Facebook share count for urls
var url = "https://graph.facebook.com/?ids=http://google.pt,http://www.github.com";"
try
{
string json = string.Empty;
using (WebClient client = new WebClient())
{
json = client.DownloadString(url);
}
@pedroadaodev
pedroadaodev / MailChimpApiListAddContact.cs
Last active February 15, 2018 11:27
MailChimp API add contact to list
// mailchimp API add member to list
// http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/
// how to get my Id List
// https://kb.mailchimp.com/lists/manage-contacts/find-your-list-id
var listId = "myListId";
var url = "https://us3.api.mailchimp.com/3.0/lists/" + listId + "/members";
using (HttpClient client = new HttpClient())
@pedroadaodev
pedroadaodev / robots.txt
Last active January 4, 2018 16:27
Sitemap.xml and robots.txt with Umbraco
User-agent: *
Sitemap: https://www.mywebsite.com/Sitemap.ashx
@pedroadaodev
pedroadaodev / Test.cs
Last active November 11, 2017 17:17
Umbraco Content Guid
// for document
var udi = new GuidUdi("document", myCurrentNode.GetGuid());
// for media
var image = UmbracoHelperContext.TypedMedia(1100);
var udi = new GuidUdi("media", image.GetGuid());
// using content service to update images field
product.SetValue("images", udi.ToString());
@pedroadaodev
pedroadaodev / PaginationModel.cs
Last active April 27, 2017 11:08
Simple pagination buttons - bootstrap template
public class PaginationModel
{
public int ItemsPerPage { get; set; }
public int CurrentPage { get; set; }
public int ListTotalItems { get; set; }
}
@pedroadaodev
pedroadaodev / UrlRewriting.config
Last active July 17, 2017 10:28
Don't use /umbraco/urlRewriting.config because its slow, very slow. Use it on web.config.
<?xml version="1.0" encoding="utf-8"?>
<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<!--
URLRewriting.net is obsolete and will be removed from Umbraco in the future.
If you want to do rewrites, make sure to use IIS URL rewrite: https://www.iis.net/downloads/microsoft/url-rewrite
The advantage of using IIS rewrite is that it is much faster, much less CPU intensive and much less memory intensive.
-->
<add name="CarDetail"
virtualUrl="^~/2017/car/detail/(.*)"