Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Upgrading SilverStripe /

Ask questions about upgrading SilverStripe to the latest version.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Out of memory fatal error after 2.4 > 3.1.8 upgrade


Go to End


9 Posts   3982 Views

Avatar
Mr. Neave

Community Member, 23 Posts

4 January 2015 at 9:59pm

Two types of custom page are creating an out of memory error when viewing the published page. The admin for both custom page types works fine.

Previously these worked on 2.4 so it may be that I’ve missed something whilst upgrading to 3.1.8.

There are some ugly loops in there that may have been the cause, but commenting them out doesn’t seem to remedy the issue.

Here’s the first type of page, which causes an error in /framework/control/Director.php on line 769:

<?php
class Artist extends Page
{
	// parent page type
	static $default_parent = 'ArtistList';

	// disable child pages
	static $allowed_children = array();
	
    // db fields
    static $db = array (
        'Description' => 'HTMLText'
    );

    // relations
    static $belongs_many_many = array (
		'Artworks' => 'Artwork'
    );
	static $has_many = array (
		'SampleArtworks' => 'SampleArtwork'
	);
	static $has_one = array(
      'Thumbnail' => 'Image'
	);

	// fields for CMS
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        
		$desc_field = New HtmlEditorField('Description');
		
		$sample_artworks = new GridField('SampleArtworks', null, $this->SampleArtworks(), GridFieldConfig_RelationEditor::create());
		
        $thumbnail_field = new UploadField('Thumbnail', 'Thumbnail');
		$thumbnail_field->setFolderName('Uploads/artist_thumbnails/');

        $fields->removeFieldFromTab("Root.Main", 'Content');
		$fields->renameField("Title", "Name");
        $fields->addFieldToTab("Root.Main", $desc_field);
        $fields->addFieldToTab("Root.Thumbnail", $thumbnail_field);
        $fields->addFieldToTab("Root.Samples of work for profile page", $sample_artworks);
         
        return $fields;
    }

	// retrieve all exhibitions featuring artworks by this artist
    public function Exhibitions() {
        $return = new DataList('Exhibition');
        // $exhibitions = DataObject::get('Exhibition');
        // foreach($exhibitions as $exhibition) {
        //     $artists = $exhibition->Artists();
        //     if($artists->byID($this->ID) && !$return->byID($exhibition->ID)) {
        //         $return->push($exhibition);
        //     }   
        // }
        return $return;
    }
}
class Artist_Controller extends Page_Controller {
}

And the second type of page, which causes an error in /framework/core/Config.php on line 577:

<?php
class Exhibition extends Page
{
	// parent page type
	private static $default_parent = 'ExhibitionList';

	// disable child pages
	private static $allowed_children = array();
	
    //db fields
    private static $db = array (
        'StartDate' => 'Date',
        'EndDate' => 'Date',
		'Description' => 'Text'
    );

	// relations
    private static $many_many = array (
		'Artworks' => 'Artwork'
    );
	private static $has_one = array(
      'Thumbnail' => 'Image'
	);


	// fields for CMS
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
		
		$start_date_field = new DateField('StartDate', 'Start date');
		$start_date_field->setConfig('showcalendar', true);
		
		$end_date_field = new DateField('EndDate', 'End date');
		$end_date_field->setConfig('showcalendar', true);
		
		$desc_field = new TextAreaField('Description');
		
		$thumbnail_field      = new UploadField('Thumbnail', 'Thumbnail');
        $thumbnail_field->setFolderName('Uploads/exhibition_thumbnails/');
				
		$artworks = new GridField('Artworks', null, $this->Artworks(), GridFieldConfig_RelationEditor::create());

		$fields->renameField("Title", "Title");
        $fields->removeFieldFromTab("Root.Main", 'Content'); 	
		$fields->addFieldToTab("Root.Main", $start_date_field);
		$fields->addFieldToTab("Root.Main", $end_date_field);
		$fields->addFieldToTab("Root.Main", $desc_field);      	
		$fields->addFieldToTab("Root.Main Image", $thumbnail_field);         	
        $fields->addFieldToTab("Root.Artworks", $artworks); 

        return $fields;
    }

    public function Artists() {
        $artists = new DataList('Artist');
        // $artworks = $this->Artworks();
        // loop through artworks and retrieve each related artist.
        // return a dataobjectset that contains each artist only once.
        // foreach($artworks as $artwork) {
        //     $next_artists = $artwork->Artists();
        //     if($next_artists) {
        //         foreach($next_artists as $check_artist) {
        //             if(!$artists->byID($check_artist->ID)) {
        //                 $artists->push($check_artist);
        //             }
        //         }
        //     }
        // }
        return $artists;
    }

}
class Exhibition_Controller extends Page_Controller {
	function IsExhibition() { return true; }
}

Any ideas?

Avatar
nzstephenf

Community Member, 63 Posts

5 January 2015 at 3:17pm

Hey Mr. Neave,
Try adding "private" to your static...

<?php
class Artist extends Page
{
	// parent page type
	private static $default_parent = 'ArtistList';

	// disable child pages
	private static $allowed_children = array();
	
    // db fields
    private static $db = array (
        'Description' => 'HTMLText'
    );

    // relations
    private static $belongs_many_many = array (
		'Artworks' => 'Artwork'
    );
	private static $has_many = array (
		'SampleArtworks' => 'SampleArtwork'
	);
	private static $has_one = array(
      'Thumbnail' => 'Image'
	);

And then do a /dev/build and check it see if you still get fatal errors :)
Report back and let me know if you still experience problems!

Avatar
Mr. Neave

Community Member, 23 Posts

5 January 2015 at 8:33pm

Thank you for your reply nzstephenf.

Both page types still cause the fatal out of memory error, even with that fix applied.

I’ve upped the php memory limit to 1024MB just for kicks and it still runs into the ceiling, it just takes longer. Like something is stuck in a loop.

Is there anywhere else it would make sense to look to try and track down the issue?

Thanks again.
Brent

Avatar
nzstephenf

Community Member, 63 Posts

5 January 2015 at 8:58pm

Have you updated all classes that is to do with the 'Artist' class? So it all uses the private static method?

Another thing, have you double checked that your templates aren't missing them <% end_with %> <% end_loop %> syntax tags? That happens to me sometimes :)

Avatar
Mr. Neave

Community Member, 23 Posts

5 January 2015 at 9:09pm

Thanks!

Just checked with a find-in-folder, all of the static methods in mysite/code are definitely now private.

Commenting out everything in the template file and flushing doesn’t seem to make any difference.

I’m not really sure where else to look.

Avatar
Mr. Neave

Community Member, 23 Posts

5 January 2015 at 9:16pm

OK — fixed!

It looks like in 3.x you can’t have a layout template and an include template with the same filename, even though they reside in different directories (you could in 2.4).

Previously Layout/Exhibition.ss included Includes/Exhibition.ss. Changing the filename of Includes/Exhibition.ss fixed the issue.

Likewise with Layout/Artist.ss and Includes/Artist.ss.

Everything is working as it should now.

Avatar
nzstephenf

Community Member, 63 Posts

5 January 2015 at 9:45pm

Good to hear you got it fixed Brent!! :)

Sorry if my help was a tad or completely useless! I had a similar issue myself, but it was because I upgraded from 3.0.1 to 3.1.6 and compatibility issues went through the freakin' roof. Hahaha. But again, glad to hear you found the fix!

Stephen

Avatar
Mr. Neave

Community Member, 23 Posts

5 January 2015 at 9:51pm

Not useless at all. If you hadn’t picked up that those static methods were not set to private I’d still be scratching my head…Thanks for taking the time to help.

Go to Top