summaryrefslogtreecommitdiff
blob: c214ccf6c294b1d3f7f577f58de25c0349b9cac1 (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
<?

	$verbose = true;
	$qa = 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 '../class.portage.ebuild.php';
	
	// Get the arches
	$tree = new PortageTree();
	$arr_licenses = $tree->getLicenses();
	
	// Find all the ebuilds that are missing ebuild arch
	$sql = "SELECT id, metadata FROM missing_license;";
	$arr = $db->getAssoc($sql);
	
	if($verbose)
		shell::msg(count($arr)." ebuilds to check");
		
	// Get the licenses from the database
	$db_licenses = $db->getAssoc("SELECT name, id FROM license;");
	
	foreach($arr as $ebuild_id => $str) {
		
		if(!empty($str)) {
			$arr = arrLicenses($str, $arr_licenses);
		} else {
			$arr = array();
		}
		
		if(count($arr)) {
			foreach($arr as $str) {
				if($db_licenses[$str]) {
					$arr_insert = array(
						'ebuild' => $ebuild_id,
						'license' => $db_licenses[$str],
					);
					
					$db->autoExecute('ebuild_license', $arr_insert, MDB2_AUTOQUERY_INSERT);
				}
			}
		}
		
		
	}
	
	/**
	 * Create an array of the ebuild's licenses
	 *
	 * @param string licenses
	 * @return array
	 */
	function arrLicenses($str, $licenses) {
		
		$arr = explode(' ', $str);

		$arr_licenses = array();
		
		if(count($arr)) {
			
			foreach($arr as $str) {
				if(in_array($str, $licenses))
					$arr_licenses[] = $str;
			}
			
			$arr_licenses = array_unique($arr_licenses);

		}
		
		return $arr_licenses;
	}
	
	
?>