Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
system_asset_fns.inc
1 <?php
37 function system_asset_fns_create_pre_check(Asset $asset)
38 {
39  $db = DAL::getDb();
40 
41  $sql = 'SELECT COUNT(*)
42  FROM '.SQ_TABLE_RUNNING_PREFIX.'ast
43  ';
44  $where = 'type_code = :type_code';
45  $where = $GLOBALS['SQ_SYSTEM']->constructRollbackWhereClause($where);
46  $sql .= $where;
47 
48  try {
49  $query = MatrixDAL::preparePdoQuery($sql);
50  MatrixDAL::bindValueToPdo($query, 'type_code', $asset->type(), PDO::PARAM_STR);
51  $exists = MatrixDAL::executePdoOne($query);
52  } catch (Exception $e) {
53  throw new Exception('Unable to check for existing system asset of type "'.$type_code.'" due to database error: '.$e->getMessage());
54  }
55 
56  if ($exists) {
57  trigger_localised_error('CORE0085', E_USER_WARNING, $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($asset->type(), 'name'));
58  return FALSE;
59  }
60 
61  return TRUE;
62 
63 }//end system_asset_fns_create_pre_check()
64 
65 
74 function system_asset_fns_create_cleanup(Asset $asset)
75 {
76  // remove any write and admin permissions that have been set on this asset and it's dependants
77  $assetids = array_keys($GLOBALS['SQ_SYSTEM']->am->getDependantChildren($asset->id));
78  foreach ($assetids as $assetid) {
79  foreach (Array(SQ_PERMISSION_WRITE, SQ_PERMISSION_ADMIN) as $perm) {
80  $unset_perms = $GLOBALS['SQ_SYSTEM']->am->getPermission($assetid, $perm, NULL, FALSE, FALSE, TRUE);
81  foreach ($unset_perms as $userid => $access) {
82  if (!$GLOBALS['SQ_SYSTEM']->am->deletePermission($assetid, $userid, $perm)) {
83  return FALSE;
84  }
85  }
86  }
87  }
88 
89  return TRUE;
90 
91 }//end system_asset_fns_create_cleanup()
92 
93 
94 ?>