Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
delete_assets_by_id.php
1 <?php
25 error_reporting(E_ALL);
26 if ((php_sapi_name() != 'cli')) trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
27 
28 if (empty($argv[1])) {
29  echo "Supply some assetid's to move to the trash.\n";
30  echo "This only moves the assets to the trash, to really delete them, you still need to use the purge_trash.php script.\n\n";
31  echo "Usage: " . __FILE__ . " id1 id2 id3\n";
32  exit;
33 }
34 
35 require dirname(__FILE__) . '/../../core/include/init.inc';
36 
37 // set up the root user
38 $root_user = &$GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
39 // log in as root
40 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
41  echo "Failed login in as root user\n";
42  exit();
43 }
44 
45 $trash_folder = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('trash_folder');
46 
47 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
48 
49 $am = new Asset_Manager();
50 
51 $bad_ids = array();
52 
53 # argv[0] is the script name so take one off to see how many assets we're going to delete.
54 $asset_count = count($argv) - 1;
55 echo "Going to delete $asset_count assets .. \n";
56 for ($i = 1; $i <= $asset_count; $i++) {
57  if ($i % 5 == 0) {
58  echo "Have deleted $i / $asset_count assets so far .. \r";
59  }
60  $assetid = $argv[$i];
61 
62  $link = $am->getLink($assetid, NULL, '', TRUE, NULL, 'minor');
63  if (empty($link)) {
64  $bad_ids[] = $assetid;
65  continue;
66  }
67  $am->moveLink($link['linkid'], $trash_folder->id, $link['link_type'], 0);
68 }
69 
70 $GLOBALS['SQ_SYSTEM']->restoreRunLevel();
71 
72 echo "\nTrashing complete.\n";
73 if (!empty($bad_ids)) {
74  echo "I was unable to delete the following assetids:\n";
75  echo str_repeat('-', 5) . "\n";
76  echo implode($bad_ids, "\n") . "\n";
77  echo str_repeat('-', 5) . "\n";
78 }
79 
80 echo "Please run purge_trash now to really delete them.\n";
81