harvs1789uk
  1. ->exclude(array(
  2. 'NameTitle' => array(NULL, "")
  3. ));

Does not work, as it just throws NULL in the NOT IN (x, y, z) clause (surprised it doesn't error tbh)

harvs1789uk

I have the following:

  1. $leads = LMM_Lead::get()
  2. ->filter(array(
  3. 'Created:LessThan' => $oneWeekAgo,
  4. 'ManuallyCreated' => 0
  5. ))
  6. ->exclude(array(
  7. 'NameTitle' => "",
  8. 'FirstName' => "",
  9. 'LastName' => ""
  10. ));

Which results in the SQL:

  1. SELECT
  2. * #Actually loads of SS stuff
  3. FROM
  4. "LMM_Lead"
  5. WHERE
  6. ("LMM_Lead"."Created" < ?)
  7. AND ("LMM_Lead"."ManuallyCreated" = ?)
  8. AND (
  9. ("LMM_Lead"."NameTitle" != ?)
  10. OR ("LMM_Lead"."FirstName" != ?)
  11. OR ("LMM_Lead"."LastName" != ?)
  12. );

but I would feel better if I could also include OR "LMM_Lead"."NameTitle" IS NULL clauses for each of the 3 fields

harvs1789uk

Best way to check for empty values on a nullable string in the DB via the ORM (i.e. null or "") in SS 3.6 ?

harvs1789uk

I think I can get round that and prevent the loop[ by calling $video->writeToStage(Versioned::LIVE); directly instead of publishSingle() though...

harvs1789uk

Which is pretty obvious now I look at Versioned::publishSingle():

  1. // get the last published version
  2. $original = null;
  3. if ($this->isPublished()) {
  4. $original = self::get_by_stage($owner->baseClass(), self::LIVE)
  5. ->byID($owner->ID);
  6. }

It get's a fresh instance of the object from the DB...

harvs1789uk

Well...that almost works, except $original doesn't contain any non-persistent properties I set like $this->owner->SkipExtendedPublicationWorkflow = true; so I get the infinite loop as feared...

harvs1789uk

>or do you mean saving it against the file itself? ^ Yes

Also, I do some tasks when it's already set, on all publications, like refresh the embed code

harvs1789uk

$original gets passed into onAfterPublish(), I am thinking set a temporary, non-DB, property on the object, then check for it's existence at the top of onAfterPublish() e.g.

  1. public function onAfterPublish($original) {
  2. if (!empty($original)
  3. && is_object($original)
  4. && $original->SkipExtendedPublicationWorkflow
  5. ) {
  6. return false;
  7. }
  8.  
  9. // Do stuff
  10.  
  11. $this->owner->SkipExtendedPublicationWorkflow = true;
  12. $this->owner->singlePublish();
  13. }
harvs1789uk

However, I suspect I am in for some shit when I try to update $this->owner-VimeoURI etc in this publication flow, and then save/publish the File again to store it....that'll lead to potential infinite loops, like calling ->write() within an onAfterWrite()

harvs1789uk

Prints out in my error_log as and when expected