Skip to content

Instantly share code, notes, and snippets.

@stojg
Created March 23, 2014 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stojg/9729134 to your computer and use it in GitHub Desktop.
Save stojg/9729134 to your computer and use it in GitHub Desktop.
Example Create a bunch of dataobjects in a SilverStripe task
<?php
/**
* CreateSomething
*
* Create a bunch of dataobjects, in this case 10 Members.
*
*/
class CreateSomething extends BuildTask {
public function run($request) {
for($index = 1; $index <= 10; $index++) {
$existing = Member::get()->filter('Email', 'test'.$index.'@test.com');
if(!$existing->count()) {
$member = new Member(array(
'Email' => 'test'.$index.'@test.com',
'FirstName' => 'A'.$index
));
$member->write();
echo 'New Member '.$member->Email.PHP_EOL;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment