Created
March 23, 2014 20:11
-
-
Save stojg/9729134 to your computer and use it in GitHub Desktop.
Example Create a bunch of dataobjects in a SilverStripe task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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