827
|
1 #!/usr/bin/php
|
|
2 <?
|
|
3 require_once "mconfig.inc.php";
|
|
4 require_once "msite.inc.php";
|
|
5
|
|
6 stCheckCLIExec();
|
|
7
|
|
8
|
|
9 //
|
|
10 // Create directories
|
|
11 //
|
|
12 function stMakeDir($path, $perm)
|
|
13 {
|
|
14 if (!file_exists($path))
|
|
15 {
|
|
16 echo " - Creating ".$path."\n";
|
|
17 if (mkdir($path, $perm, TRUE) === false)
|
|
18 die("Could not create directory '".$path."'\n");
|
|
19 }
|
|
20 }
|
|
21
|
|
22
|
|
23 function stInitializeDirs()
|
|
24 {
|
|
25 global $setEntryPath, $setPreviewPath, $setThumbDir,
|
|
26 $setEntryPathPerms, $setPrevPathPerms;
|
|
27
|
|
28 echo "Checking for missing directories ...\n";
|
|
29 stMakeDir($setEntryPath, $setEntryPathPerms);
|
|
30 stMakeDir($setPreviewPath, $setPrevPathPerms);
|
880
|
31 stMakeDir(stMakePath(FALSE, FALSE, array($setPreviewPath, $setThumbDir)), $setPrevPathPerms);
|
827
|
32
|
|
33 foreach (stExecSQL("SELECT * FROM compos WHERE cpath <> '' AND cpath IS NOT NULL") as $compo)
|
|
34 {
|
|
35 stMakeDir(stMakePath(FALSE, FALSE, array($setEntryPath, $compo["cpath"])), $setEntryPathPerms);
|
|
36 }
|
|
37 }
|
|
38
|
|
39
|
|
40 //
|
|
41 // Main program starts
|
|
42 //
|
|
43 if ($argc < 2)
|
|
44 {
|
|
45 echo
|
|
46 "faptool - Do stuff with FAPWeb database\n".
|
|
47 "(C) Copyright 2014 ccr/TNSP\n".
|
|
48 "\n".
|
|
49 "Usage: ".$argv[0]." <mode> [args]\n".
|
|
50 "Where mode is one of following:\n".
|
|
51 "\n".
|
|
52 " init\n".
|
|
53 " Create directories for entries and previews, if needed.\n".
|
|
54 "\n".
|
|
55 "\n";
|
|
56 exit;
|
|
57 }
|
|
58
|
|
59 // Try to connect to database
|
|
60 $spec = stGetSetting("sqlDB");
|
|
61 if (($db = stConnectSQLDBSpec($spec)) === false)
|
|
62 die("Could not connect to SQL database '".$spec."'.\n");
|
|
63
|
|
64 echo "Using database spec '".$spec."'.\n";
|
|
65
|
|
66 // Fetch non-"hardcoded" settings from SQL database
|
|
67 stReloadSettings();
|
|
68
|
|
69 // Set some globals for our benefit
|
|
70 $setEntryPath = stGetSetting("entryPath");
|
|
71 $setPreviewPath = stGetSetting("previewPath");
|
|
72 $setPreviewURL = stGetSetting("previewURL");
|
|
73 $setThumbDir = stGetSetting("thumbnailSubDir");
|
832
|
74 $setEntryPathPerms = stGetSetting("entryPathPerms");
|
|
75 $setPrevPathPerms = stGetSetting("previewPathPerms");
|
827
|
76
|
|
77 if ($setEntryPath === FALSE || $setPreviewPath === FALSE ||
|
832
|
78 $setPreviewURL === FALSE || $setThumbDir === FALSE ||
|
|
79 $setEntryPathPerms === FALSE || $setPrevPathPerms === FALSE)
|
827
|
80 {
|
831
|
81 die("Some required settings not defined in mconfig.inc.php!\n");
|
827
|
82 }
|
|
83
|
|
84
|
|
85 // Act according to specified command
|
|
86 switch (substr(stCArgLC(1), 0, 4))
|
|
87 {
|
|
88 case "init":
|
|
89 //
|
|
90 // Initialize the data directories etc
|
|
91 //
|
|
92 stInitializeDirs();
|
|
93 break;
|
|
94
|
|
95 default:
|
|
96 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n";
|
|
97 break;
|
|
98 }
|
|
99
|
|
100 ?> |