예제 #1
0
 public static function addSchools()
 {
     $class = get_called_class();
     decho("Adding schools for {$class}");
     foreach (static::getSchools() as $data) {
         print_r($data);
         $school = SchoolQuery::create()->filterByBookstoreType($class)->filterBySubdomain($data['Subdomain'])->findOne();
         if (!$school) {
             $school = new School();
             $school->setBookstoreType($class)->setSubdomain($data['Subdomain']);
         }
         $school->setSlug($data['Slug'])->setName($school->getName() ?: $data['Name'])->setShortName($school->getShortName(true) ?: (isset($data['ShortName']) ? $data['ShortName'] : School::guessShortName($data['Name'], $data['Slug'])))->setTouched(1)->save();
     }
 }
예제 #2
0
    if (libxml_get_errors()) {
        echo "Errors in {$abbr}-schools.xml, skipping.\n";
        continue;
    }
    foreach ($schools->school as $school) {
        if ($obj = SchoolQuery::create()->filterBySlug($school->Slug)->findOne()) {
            if ($bookstoreType != $obj->getBookstoreType()) {
                echo "Tried to add a school for a slug that already exists, skipping: {$school->Slug}\n";
                continue;
            } else {
                $obj->setTouched(true)->save();
            }
        }
        $query = SchoolQuery::create()->filterByBookstoreType($bookstoreType);
        $obj = $query->filterBySlug($school->Slug)->findOne();
        if (!$obj) {
            $obj = new School();
            $obj->setSlug($school->Slug)->setBookstoreType($bookstoreType);
            echo "Adding new school: {$school->Slug}\n";
        }
        $obj->setName(html_entity_decode($school->Name))->setShortName(html_entity_decode($school->ShortName))->setSlug($school->Slug)->setState($school->State)->setZip($school->Zip)->setLocalTax($school->LocalTax)->setAmazonTag($school->AmazonTag ?: 'txtbks-20')->setSubdomain($school->Subdomain)->setBId($school->BId)->setTouched(1)->setEnabled(1)->save();
    }
}
$untouchedSchools = SchoolQuery::create()->filterByTouched(false)->find();
foreach ($untouchedSchools as $school) {
    if ($school->getEnabled()) {
        echo "Disabling " . $school->getSlug() . "\n";
        $school->setEnabled(0)->save();
    }
}
require_once __DIR__ . '/json.php';