summaryrefslogtreecommitdiff
blob: c5ee191b6d349f198b4ad7566178088766ebea44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?

// 	$verbose = true;

	require_once 'header.php';
	require_once 'class.portage.tree.php';
	require_once 'class.portage.category.php';
	require_once 'class.portage.package.php';
	require_once '/home/steve/svn/znurt/class.db.package.php';
	
	$sql = "SELECT id, name FROM category ORDER BY name;";
	$arr_categories = $db->getAssoc($sql);
	
	$sql = "SELECT category, package, category_name, package_name FROM view_package;";
	$arr = $db->getAll($sql);
	foreach($arr as $row) {
		$arr_package_ids[$row['category_name']][$row['package_name']] = $row['package'];
	}
	
	$sql = "SELECT MAX(ctime) max_ctime, MAX(mtime) max_mtime FROM package;";
	$arr = $db->getRow($sql);
	if(is_array($arr))
		extract($arr);
	
	$table = 'package';
	
	foreach($arr_categories as $category_id => $category_name) {
	
		$obj_category = new PortageCategory($category_name);
		
		$arr_packages = $obj_category->getPackages();
		
		$arr_diff = importDiff('package', $arr_packages, "category = $category_id");
		
		if(count($arr_diff['delete'])) {
			foreach($arr_diff['delete'] as $name) {
				$sql = "DELETE FROM $table WHERE name = ".$db->quote($name)." AND category = $category_id;";
				$db->query($sql);
			}
		}
		
		if(count($arr_diff['insert'])) {
		
			foreach($arr_diff['insert'] as $package_name) {
			
				$obj_package = new PortagePackage($obj_category->name, $package_name);
			
 				$arr_insert = array('category' => $category_id, 'name' => $package_name, 'changelog' => $obj_package->changelog);
				$db->autoExecute($table, $arr_insert, MDB2_AUTOQUERY_INSERT);
			}
		}
		
		foreach($arr_packages as $package_name) {
			
			if($verbose) {
				shell::msg("$category_name/$package_name");
			}
		
			if(!in_array($package_name, $arr_diff['insert'])) {
				$package_id = $arr_package_ids[$category_name][$package_name];
				
				if($package_id) {
				
					$p = new PortagePackage($obj_category->name, $package_name);
					
					if(($p->mtime > $max_mtime) || ($p->ctime > $max_ctime)) {
					
						if($verbose) {
							shell::msg("Updating $category_name/$package_name id: $package_id");
						}
					
						$db_package = new DBPackage($package_id);
						
						if($p->mtime != $db_package->mtime)
							$db_package->mtime = $p->mtime;
						if($p->ctime != $db_package->ctime)
							$db_package->ctime = $p->ctime;
						if($p->changelog != $db_package->changelog)
							$db_package->changelog = $p->changelog;
							
					
					}
						
				}
			}
		}
		
	}
	
?>