We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39498
    • 169 Posts
    I want to achive the following:
    A ressource with two date tvs (start/end) is beeing created.
    1. As the ressource gets saved, the end date tv should populate the unpublish date automatically.
    2. Nightly all unpublished ressources of a folder should be moved in a subfolder, eg. archive.
    Are there any solutions for that already?
      • 39498
      • 169 Posts
      for 1. I got this as a plugin on OnDockFormSave now
      <?php
      switch ($modx->event->name) {
          case 'OnDocFormPrerender':
              break;
          case 'OnDocFormRender':
      		break;
          case 'OnDocFormSave':
      		if ($scriptProperties['resource']->get('template')==2) { // prüfen ob template 2 (Event)
      		  $myId = $scriptProperties['resource']->get('id');
      		  $page = $modx->getObject('modResource', $myId);
      		  $myEventStart = $page->getTVValue('eventstart');
      		  $myEventEnde = $page->getTVValue('eventend');
        
      		  $resource =& $scriptProperties['resource'];
      		  if (empty($myEventEnde)) {  //EventStart +1 setzen
      			  $myEventStart = strtotime("+1 day", strtotime($myEventStart));
      			  $resource->set('unpub_date',$myEventStart);
      		  } else {  //EventEnde +1 setzen
      			  $myEventEnde = strtotime("+1 day", strtotime($myEventEnde));
      			  $resource->set('unpub_date',$myEventEnde);
      		  };
      		  $resource->save();
      		};
              break;
      }
      return;
        • 40045
        • 534 Posts
        For 2. you probably need a combination of a cron job (run at 2am or so, just calling the page with curl or so) and maybe a resource to call or a plugin to attach to OnHandleRequest (maybe also listening to some GET variable or so to identify the archiver script when run via cronjob).

        The snippet or plugin would look for unpublished resources in a specified parent and move them to another parent (archive container or whatever), somethink like this (untested):

        $resources = $modx->getCollection('modResource', array('unpublished' => true, 'parent' => id of events container));
        
        if (!empty($resources) {
        	foreach ( $resources as $resource ) {
        		$resource->fromArray(array(
        			'parent' => id of archive container
        		));
        		$resource->save();
        	}
        }