andante

something like $exception = new Exception(); $stackTrace = $e->getTraceAsString(); Log::error($stackTrace); or whatever the proper syntax is

andante

if you want, you can create a new exception and get a stack trace from there

Randika Jeewantha

hi guys, is there any method to write error log file with stack trace, documentation code only give error and related line number. i need stack trace with error to write error log file.

null

queue a job to start "after a certain time period" that does your DB write for you

👍 (1)
null

any kind of scheduling requirement would need to be satisfied with queuedjobs, or similar

SilentDesigns

If I manually add a user to a permissions group via the CMS, is there a way that I can automatically remove them from that group after a certain time period, e.g. 12 months?

nightjarnz

There's work going on by core contributor @dhensby to update compatibility to PHPUnit 8 IIRC. You could look at that branch/PR/issue, if you're interested. I don't have a link sorry, but I'm sure if you type "phpunit" into the search at https://github.com/silverstripe/silverstripe-framework/issues you'll probably find something :)

mcameron

Is it possible to use PHPUnit version 8 or 9 with Silverstripe 4.5 or are we stuck using version 5.7? I keep getting a PHP Fatal error: Uncaught Error: Class 'SilverStripe\Dev\SapphireTest' not found in ... .

marvin

Hmmm ? > [Emergency] Uncaught Error: Class ‘App\MyProject\StudyPage’ not found > GET / > Line 5 in /var/www/mysite/www/app/src/StudyPage.php > Source > 32 $fields->addFieldToTab(“Root.Sidebar”, HTMLEditorField::create(‘Sidebar’)); > 33 $fields->addFieldToTab(“Root.Image”, new UploadField(‘FeaturedImage’)); > 34 return $fields; > 35 } > 36 }

jkersu

Can you show what you currently have in StudyPage.php?

marvin

Hi @jkersu, you mean does the page display? Yes. Is it using the correct template? Yes. Is it showing FeaturedImage? Yes. Is it showing Sidebar? No.

jkersu

The code for StudyPage. Whats in it at the moment?

marvin

Oops!!

Files: Requires logging in with Slack to view/download
StudyPage.php
jkersu

right.... the var_dump can't be put there. You need to move it inside a function

jkersu
  1. <?php
  2.  
  3. namespace App\MyProject;
  4.  
  5. use \Page;
  6. use SilverStripe\Forms\FieldList;
  7. use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
  8. use SilverStripe\Assets\Image;
  9. use SilverStripe\AssetAdmin\Forms\UploadField;
  10.  
  11. class StudyPage extends Page
  12. {
  13. /**
  14.   * @var string
  15.   */
  16. private static $table_name = 'StudyPage';
  17.  
  18. private static $has_one = [
  19. 'FeaturedImage' => Image::class,
  20. ];
  21.  
  22. private static $db = [
  23. 'Sidebar' => 'HTMLText'
  24. ];
  25.  
  26. public function getCMSFields()
  27. {
  28. $fields = parent::getCMSFields();
  29. $fields->addFieldToTab("Root.Sidebar", HTMLEditorField::create('Sidebar'));
  30. $fields->addFieldToTab("Root.Image", new UploadField('FeaturedImage'));
  31.  
  32. return $fields;
  33. }
  34.  
  35.  
  36. public function getTestSidebar() {
  37. var_dump(StudyPage::get()->byID(42)->Sidebar);
  38. die;
  39. }
  40. }
marvin

Very interesting… text content (and just the sidebar text content) just appeared! `

  1. /var/www/mysite/www/app/src/StudyPage.php:28:string '<p>This is some stuff that goes in the sidebar. I'd forgotten this field was here!!</p>' (length=87)

`

jkersu

Ok what about if you change it to the following:

  1. public function getTestSidebar() {
  2. var_dump($this-ID);
  3. var_dump($this->Sidebar);
  4. }

What does it show?

marvin

[Warning] Use of undefined constant ID - assumed ‘ID’ (this will throw an Error in a future version of PHP) GET /home/underwater-solutions?flush=1 Line 28 in /var/www/mysite/www/app/src/StudyPage.php Source

  1. 19 ];
  2. 20 public function getCMSFields()
  3. 21 {
  4. 22 $fields = parent::getCMSFields();
  5. 23 $fields->addFieldToTab("Root.Sidebar", HTMLEditorField::create('Sidebar'));
  6. 24 $fields->addFieldToTab("Root.Image", new UploadField('FeaturedImage'));
  7. 25 return $fields;
  8. 26 }
  9. 27 public function getTestSidebar() {
  10. 28 var_dump($this-ID);
  11. 29 var_dump($this->Sidebar);
  12. 30 die;
  13. 31 }
  14. 32 }

meaning??

jkersu

Sorry need to fix the arrow, should be: var_dump($this->ID); on Line 28

marvin

Thanks @jkersu — a bit more:

  1. /var/www/mysite/www/app/src/StudyPage.php:28:int 42
  2. /var/www/mysite/www/app/src/StudyPage.php:29:string '<p>This is some stuff that goes in the sidebar. I'd forgotten this field was here!!</p>' (length=87)
jkersu

Ok, now just change it to:

  1. public function getSidebarHTML() {
  2. return $this->Sidebar;
  3. }

And in template, change $getTestSidebar to $getSidebarHTML & you should be good to go

marvin

Wow! You cracked it @jkersu — thanks heaps for your help!!

👍 (1)

Show less replies