API CHANGE Removed import() and generateProductGroups() from DatabaseAdmin - custom code for ecommerce module

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@54162 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-05-08 00:27:09 +00:00
parent 2ea476d90b
commit d2f13f90e9

View File

@ -262,183 +262,6 @@ class DatabaseAdmin extends Controller {
} }
/**
* Imports objects based on a specified CSV file in $_GET['FileName']
*/
function import(){
$FileName = $_GET['FileName'];
$FileName = $_SERVER['DOCUMENT_ROOT'] .
substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF'])-18) .
"/assets/" . $FileName;
if(file_exists($FileName)) {
$handle = fopen($FileName,'r');
if($handle){
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
if($row == 1){
for ($c=0; $c < $num; $c++) {
$ColumnHeaders[] = str_replace(' ','',$data[$c]);
// Have to add code here to remove unsafe chars..
}
} else {
$Product = new Product();
for ($c=0; $c < $num; $c++) {
$Product->$ColumnHeaders[$c] = trim($data[$c]);
}
$MainCategory = DataObject::get("ProductGroup",
"URLSegment LIKE '" . $Product->generateURLSegment(
$Product->Category) ."'");
if(!$MainCategory) {
// if we can't find a main category, create all three sub
// categories, as they must be unique.
$ProductGroup = new ProductGroup();
$ProductGroup->Title = $Product->Category;
print_r("<ul><li>Created : $ProductGroup->Title</li>");
$ProductGroup->ParentID = 1;
$index = $ProductGroup->write();
$ProductGroup->flushCache();
if($Product->SubCategory) {
$ChildProductGroup = new ProductGroup();
$ChildProductGroup->Title = $Product->SubCategory;
print_r("<ul><li>Created : $ChildProductGroup->Title</li>");
$ChildProductGroup->ClassName = "ProductGroup";
$ChildProductGroup->ParentID = $index;
$index = $ChildProductGroup->write();
$ChildProductGroup->flushCache();
}
if($Product->SubCategory2) {
$NestedProductGroup = new ProductGroup();
$NestedProductGroup->Title = $Product->SubCategory2;
print_r("<ul><li>Created : $NestedProductGroup->Title</li>");
$NestedProductGroup->ClassName = "ProductGroup";
$NestedProductGroup->ParentID = $index;
$index = $NestedProductGroup->write();
$NestedProductGroup->flushCache();
}
} else {
// We've found a main category. check if theres a second...
print_r("<ul><li>USING : $MainCategory->Title</li>");
$index = $MainCategory->ID;
$SubCategory = DataObject::get_one("ProductGroup",
"URLSegment LIKE '" . $Product->generateURLSegment(
$Product->SubCategory) ."'");
if(!$SubCategory && $Product->SubCategory) {
$ChildProductGroup = new ProductGroup();
$ChildProductGroup->Title = $Product->SubCategory;
print_r("<ul><li>Created : $ChildProductGroup->Title</li>");
$ChildProductGroup->ClassName = "ProductGroup";
$ChildProductGroup->ParentID = $index;
$index = $ChildProductGroup->write();
$ChildProductGroup->flushCache();
if($Product->SubCategory2) {
$NestedProductGroup = new ProductGroup();
$NestedProductGroup->Title = $Product->SubCategory2;
print_r("<ul><li>$NestedProductGroup->Title</li>");
$NestedProductGroup->ClassName = "ProductGroup";
$NestedProductGroup->ParentID = $index;
$index = $NestedProductGroup->write();
$NestedProductGroup->flushCache();
$index = $SubCategory2->ID;
}
} else if($Product->SubCategory){
print_r("<ul><li>USING : $SubCategory->Title</li>");
$index = $SubCategory->ID;
$SubCategory2 = DataObject::get_one("ProductGroup",
"URLSegment LIKE '" . $Product->generateURLSegment(
$Product->SubCategory2) ."'");
if($Product->SubCategory2) {
$NestedProductGroup = new ProductGroup();
$NestedProductGroup->Title = $Product->SubCategory2;
print_r("<ul><li>$NestedProductGroup->Title</li>");
$NestedProductGroup->ClassName = "ProductGroup";
$NestedProductGroup->ParentID = $index;
$index = $NestedProductGroup->write();
$NestedProductGroup->flushCache();
$index = $SubCategory2->ID;
}
}
}
$MatchedProduct = DataObject::get_one("Product",
"URLSegment LIKE '" . $Product->generateURLSegment(
$Product->Title) . "'");
if($MatchedProduct) {
// create the new parents / assign many many
$MatchedProduct->ParentID = $index;
// create the new product
$MatchedProduct->write();
$MatchedProduct->flushCache();
print_r(" <h4>UPDATED</h4></ul></ul></ul><br/><br/>");
} else {
// save the new product
$Product->ParentID = $index;
$Product->write();
$Product->flushCache();
print_r(" <h4>New Product $product->Title</h4></ul></ul></ul><br/><br/>");
}
}
}
fclose($handle);
} else {
print_r("<h1>Error: Could not open file.</h1>");
}
} else {
print_r("<h1>Error: Could not open file.</h1>");
}
}
/**
* Imports objects based on a specified CSV file in $_GET['FileName']
*/
function generateProductGroups() {
$FileName = $_GET['FileName'];
$FileName = $_SERVER['DOCUMENT_ROOT'] .
substr($_SERVER['PHP_SELF'], 0, strlen($_SERVER['PHP_SELF']) - 18) .
"/assets/" . $FileName;
if(file_exists($FileName)) {
$handle = fopen($FileName,'r');
if($handle) {
$i = 0;
while(($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$ProductGroup[$i] = $data[0];
if($data[1]) {
$ProductGroup[$i][] = $data[1];
}
if($data[2]) {
$ProductGroup[$i][][] = $data[2];
}
}
} else {
print_r("<h1>Error: Could not open file.</h1>");
}
} else {
print_r("<h1>Error: Could not open file.</h1>");
}
}
/** /**
* This method does nothing at the moment... * This method does nothing at the moment...
*/ */