Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 13, 2018 @ 08:11
    Lewis Smith
    0

    Move page to trash using SQL

    Hi all,

    I'm trying to create a scheduled task that runs every x amount of time that can move a page to the trash can where the requirement is met. Oh and this has to be done through SQL as the scheduled task is run as a windows task meaning it has no link to the Umbraco project, just has access to the database!

    In the umbracoNode table, there is a 'trashed' row so I thought changing this would move the page to the trashcan but I was wrong!

    Could anyone shed some light on why just setting the trashed from 0 to 1 hasn't moved the page to the trash can and what else I need to do?!

    Thanks all, Lewis

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 13, 2018 @ 08:52
    Michaël Vanbrabandt
    1

    Hi Lewis,

    why use the Windows Task Scheduler and not the builtin scheduler of umbraco or hangfire?

    Then you have access to the service api of Umbraco to properly move the node to the recycle bin.

    <scheduledTasks>
        <!-- add tasks that should be called with an interval (seconds) -->
        <!--    <task log="true" alias="test60" interval="60" url="http://localhost/umbraco/test.aspx"/>-->
      </scheduledTasks>
    

    Hope this helps.

    /Michaël

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 13, 2018 @ 13:28
    Lewis Smith
    0

    Hi Michael,

    I was going to do this but couldnt get it working. I was pointing the url in the task to my controller /umbraco/surface/controllername/method and it wouldnt hit it.

    Could you give me a link to some docs on the service api?

    Thanks, Lewis

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 13, 2018 @ 14:13
    Michaël Vanbrabandt
    1

    Hi lewis,

    I am not at my desk atm. When I am back I will see if I can find some usefull links.

    /Michaël

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 15, 2018 @ 11:37
    Michaël Vanbrabandt
    0

    Hi Lewis,

    is it possible to show us the controller and the task defined in the scheduled taks config which causes troubles?

    Thanks!

    /Michaël

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 07:06
    Lewis Smith
    0

    Hi Michael,

    This is my controller:

    using Umbraco.Web.Mvc;
    
    namespace handt.Controllers
    {
        public class RemoveSoldProductsController : SurfaceController
        {
            public static string RemoveSoldProducts()
            {
                return "hit me";
            }
        }
    }
    

    As simple as it comes

    This is my scheduled task:

    <scheduledTasks>
        <!-- add tasks that should be called with an interval (seconds) -->
        <task log="true" alias="test60" interval="10" url="https://localhost:61884/umbraco/Surface/RemoveSoldProducts/RemoveSoldProducts"/>
    </scheduledTasks>
    

    Thanks, Lewis

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 16, 2018 @ 07:38
    Michaël Vanbrabandt
    0

    Hi Lewis,

    what do you see when you hit the url in the browser?

    https://localhost:61884/umbraco/Surface/RemoveSoldProducts/RemoveSoldProducts
    

    Also, why do you declare your method static?

    Thanks!

    /Michaël

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 08:39
    Lewis Smith
    0

    I get the following:

    Not sure why its static, I'm still learning the who MVC side of things!

    Thanks, Lewis

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 16, 2018 @ 08:42
    Michaël Vanbrabandt
    1

    Lewis,

    remove the static part and hit it again.

    Hope this helps!

    /Michaël

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 08:56
    Lewis Smith
    0

    Got it!

    Thanks Michael!!!!

    Now just to come up with the SQL -_-

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 16, 2018 @ 09:12
    Michaël Vanbrabandt
    0

    Hi Lewis,

    no need for SQL that's why you use this controller to have access to the services of Umbraco!

    Take a look at the link that @Dave has posted.

    Have a nice day!

    /Michaël

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 16, 2018 @ 09:05
    Dave Woestenborghs
    0

    Hi Lewis,

    You don't need the sql. You can use the content service to do this.

    In your controller action this available under this.Services.ContentService

    Then you can use the MoveToRecycleBin method https://our.umbraco.org/apidocs/csharp/api/Umbraco.Core.Services.ContentService.html#UmbracoCoreServicesContentServiceMoveToRecycleBinUmbracoCoreModelsIContentSystemInt32_

    Dave

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 09:44
    Lewis Smith
    0

    Hi Dave,

    So got that in there! When passing the parameters into the MoveToRecyceBin method i have to pass in IContent, Can i pass the node ID in here? At the moment this is my process:

    When a product is purchased this product gets saved to a table with details such as alias, nodeId, title, time sold, delete time and if its deleted or not.

    My task that now gets hit (yess) will run every hour or so, if the current time is > the delete time of the item in the database then teh item will be moved to the recycle bin!

    If i cant use the nodeId what other info is required that i can pass into the MoveToRecycleBin method?

    Thanks, Lewios

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 16, 2018 @ 09:48
    Michaël Vanbrabandt
    0

    Hi Lewis,

    you can use the contentservice to get the content object:

    https://our.umbraco.org/documentation/reference/management/services/contentservice#getbyidint-id

    So if you have an id, you just call the contentservice like above to get the content object and then you can pass this into the MoveToRecycleBin method.

    Hope this helps.

    /Michaël

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 09:51
    Lewis Smith
    0

    So something like this:

    var ContentService = this.Services.ContentService;
    var NodeId = Umbraco.Content(3143);      
    ContentService.MoveToRecycleBin(NodeId);
    

    Thanks, Lewis

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 09:54
    Lewis Smith
    1

    Didnt see the get id part!

    ContentService.MoveToRecycleBin(this.Services.ContentService.GetById(3143)); 
    

    Works a treat!

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 16, 2018 @ 09:56
    Michaël Vanbrabandt
    0

    Hi Lewis,

    nice to see you have found the solution!

    Have a nice day.

    /Michaël

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 11:30
    Lewis Smith
    0

    Hi Michael,

    One last thing! I now have everything working as expected when I hit the controller URL myself, but the scheduled task doesn't actually do anything... I have a breakpoint in the controller and this doesn't get hit at all.

    Is there anything wrong with the task itself?

    <scheduledTasks>
        <!-- add tasks that should be called with an interval (seconds) -->
        <task log="true" alias="test60" interval="60" url="https://localhost:61884/umbraco/Surface/RemoveSoldProducts/RemoveSoldProducts"/>
      </scheduledTasks>
    

    When entering the URL myself it works as expected. But that's all.

    Thanks, Lewis

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 16, 2018 @ 11:44
    Michaël Vanbrabandt
    0

    Hi Lewis,

    I see https://... could this be the issue? And isn't is http://... ?

    Hope this helps!

    /Michaël

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 12:50
    Lewis Smith
    0

    My VS is running over https:// so this shouldnt be an issue?

    Thanks, Lewis

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 16, 2018 @ 12:56
    Michaël Vanbrabandt
    0

    Lewis,

    ok and what about the log files? Do you see anything there?

    /Michaël

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 13:28
    Lewis Smith
    0

    Nothing in there that i dont expect!

    This is my full logs from start up:

    2018-04-16 14:25:00,347 [P63608/D2/T1] INFO  Umbraco.Core.CoreBootManager - Umbraco 7.7.7 application starting on HD01673
     2018-04-16 14:25:00,393 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Determining hash of code files on disk
     2018-04-16 14:25:00,410 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Hash determined (took 17ms)
     2018-04-16 14:25:00,450 [P63608/D2/T1] INFO  Umbraco.Core.MainDom - Acquiring MainDom...
     2018-04-16 14:25:00,452 [P63608/D2/T1] INFO  Umbraco.Core.MainDom - Acquired MainDom.
     2018-04-16 14:25:00,454 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IDiscoverable
     2018-04-16 14:25:00,711 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IDiscoverable (took 256ms)
     2018-04-16 14:25:00,712 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IApplicationStartupHandler
     2018-04-16 14:25:00,714 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IApplicationStartupHandler (took 2ms)
     2018-04-16 14:25:00,751 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IDiscoverable
     2018-04-16 14:25:00,751 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IDiscoverable (took 0ms)
     2018-04-16 14:25:00,751 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving Umbraco.Core.PropertyEditors.IPropertyEditorValueConverter
     2018-04-16 14:25:00,753 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved Umbraco.Core.PropertyEditors.IPropertyEditorValueConverter (took 1ms)
     2018-04-16 14:25:00,754 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IDiscoverable
     2018-04-16 14:25:00,754 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IDiscoverable (took 0ms)
     2018-04-16 14:25:00,754 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving Umbraco.Core.PropertyEditors.IPropertyValueConverter
     2018-04-16 14:25:00,755 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved Umbraco.Core.PropertyEditors.IPropertyValueConverter (took 1ms)
     2018-04-16 14:25:00,764 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IDiscoverable
     2018-04-16 14:25:00,764 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IDiscoverable (took 0ms)
     2018-04-16 14:25:00,764 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving Umbraco.Web.Mvc.SurfaceController
     2018-04-16 14:25:00,765 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved Umbraco.Web.Mvc.SurfaceController (took 0ms)
     2018-04-16 14:25:00,765 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IDiscoverable
     2018-04-16 14:25:00,765 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IDiscoverable (took 0ms)
     2018-04-16 14:25:00,765 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolving Umbraco.Web.WebApi.UmbracoApiController
     2018-04-16 14:25:00,766 [P63608/D2/T1] INFO  Umbraco.Core.PluginManager - Resolved Umbraco.Web.WebApi.UmbracoApiController (took 0ms)
     2018-04-16 14:25:01,787 [P63608/D2/T1] INFO  Umbraco.Core.DatabaseContext - CanConnect = True
     2018-04-16 14:25:01,929 [P63608/D2/T1] INFO  Umbraco.Web.Cache.CacheRefresherEventHandler - Initializing Umbraco internal event handlers for cache refreshing
     2018-04-16 14:25:04,104 [P63608/D2/T1] INFO  Umbraco.Web.Search.ExamineEvents - Initializing Examine and binding to business logic events
     2018-04-16 14:25:04,104 [P63608/D2/T1] INFO  Umbraco.Web.Search.ExamineEvents - Adding examine event handlers for index providers: 11
     2018-04-16 14:25:04,146 [P63608/D2/T1] INFO  Umbraco.Core.CoreBootManager - Umbraco application startup complete (took 3877ms)
     2018-04-16 14:25:04,708 [P63608/D2/T11] INFO  Umbraco.Core.Sync.ApplicationUrlHelper - ApplicationUrl: http://localhost/umbraco (UmbracoModule request)
     2018-04-16 14:25:05,073 [P63608/D2/T11] INFO  umbraco.content - Load Xml from file...
     2018-04-16 14:25:05,082 [P63608/D2/T11] INFO  umbraco.content - Loaded Xml from file.
     2018-04-16 14:25:05,887 [P63608/D2/T11] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IDiscoverable
     2018-04-16 14:25:05,888 [P63608/D2/T11] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IDiscoverable (took 0ms)
     2018-04-16 14:25:05,888 [P63608/D2/T11] INFO  Umbraco.Core.PluginManager - Resolving Umbraco.Core.PropertyEditors.IParameterEditor
     2018-04-16 14:25:05,888 [P63608/D2/T11] INFO  Umbraco.Core.PluginManager - Resolved Umbraco.Core.PropertyEditors.IParameterEditor (took 0ms)
     2018-04-16 14:25:07,643 [P63608/D2/T11] INFO  Umbraco.Core.PluginManager - Resolving umbraco.interfaces.IDiscoverable
     2018-04-16 14:25:07,643 [P63608/D2/T11] INFO  Umbraco.Core.PluginManager - Resolved umbraco.interfaces.IDiscoverable (took 0ms)
     2018-04-16 14:25:07,643 [P63608/D2/T11] INFO  Umbraco.Core.PluginManager - Resolving Umbraco.Core.Deploy.IServiceConnector
     2018-04-16 14:25:07,644 [P63608/D2/T11] INFO  Umbraco.Core.PluginManager - Resolved Umbraco.Core.Deploy.IServiceConnector (took 0ms)
    

    Doesn't give me an error stating that it cant find the path or anything..!

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 16, 2018 @ 13:31
    Dave Woestenborghs
    0

    Hi Lewis,

    I see you scheduled task is configured for this url : https://localhost:61884

    But you run Umbraco using this url : http://localhost/umbraco accordng to this log line

    2018-04-16 14:25:04,708 [P63608/D2/T11] INFO  Umbraco.Core.Sync.ApplicationUrlHelper - ApplicationUrl: http://localhost/umbraco (UmbracoModule request)
    

    Can you check the config mentioned in my other answer ?

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 16, 2018 @ 13:09
    Dave Woestenborghs
    0

    Hi Lewis,

    Can you set your log level to DEBUG and check if there is a mention of "Does not run on slave servers" ?

    Also can you check what you have configured as umbracoApplicationUrl https://our.umbraco.org/documentation/Reference/Config/umbracoSettings/#webrouting

    If this is not set Umbraco will try to find it from the request. This url is also used for the scheduler.

    Dave

  • Lewis Smith 208 posts 617 karma points c-trib
    Apr 16, 2018 @ 13:30
    Lewis Smith
    0

    How do I set my log level to debug? I'm running the project on debug mode? I have also searched the solution for 'Does not run on slave servers'

    This is what i have in my umbracoSettings:

    <web.routing trySkipIisCustomErrors="true" internalRedirectPreservesTemplate="false" disableAlternativeTemplates="false" disableFindContentByIdPath="false" umbracoApplicationUrl="">
    </web.routing>
    
Please Sign in or register to post replies

Write your reply to:

Draft