Guest User

Untitled

a guest
Dec 2nd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4.  
  5. # UTILS
  6. usage() {
  7. echo ""
  8. echo "SUPER FLATTEN"
  9. echo "-------------"
  10. echo "This script clean your eZ Publish database by removing unused entries"
  11. echo ""
  12. echo "Usage: ${0} <database_name> <database_user> <database_password>"
  13. echo ""
  14. }
  15.  
  16. mysql_execute() {
  17. mysql -NB -u${DATABASE_USER} -p${DATABASE_PASSWORD} -hlocalhost -D${DATABASE_NAME} -e"$1"
  18. }
  19.  
  20.  
  21.  
  22. # ARGUMENT CONTROL
  23. if [ $# -ne 3 ]
  24. then
  25. usage
  26. exit
  27. fi
  28.  
  29.  
  30.  
  31. # VARIABLES
  32. DATABASE_NAME=${1}
  33. DATABASE_USER=${2}
  34. DATABASE_PASSWORD=${3}
  35.  
  36.  
  37.  
  38. # GET CON
  39. TIME_BEFORE="$(date +%s)"
  40.  
  41. echo "Clean contentobject"
  42. mysql_execute "DELETE FROM ezcontentobject WHERE id NOT IN (SELECT contentobject_id FROM ezcontentobject_tree);"
  43.  
  44. echo "Clean contentobject tree node"
  45. mysql_execute "DELETE FROM ezcontentobject_tree WHERE contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  46. mysql_execute "DELETE FROM eznode_assignment WHERE contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  47.  
  48. echo "Clean contentobject attribute (could be long)"
  49. mysql_execute "DELETE FROM ezcontentobject_attribute WHERE contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  50.  
  51. echo "Clean contentobject version"
  52. mysql_execute "DELETE FROM ezcontentobject_version WHERE contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  53.  
  54. echo "Clean contentobject name"
  55. mysql_execute "DELETE FROM ezcontentobject_name WHERE contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  56.  
  57. echo "Clean contentobject name"
  58. mysql_execute "DELETE FROM ezcontentobject_name WHERE contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  59.  
  60. echo "Clean contentobject link"
  61. mysql_execute "DELETE FROM ezcobj_state_link WHERE contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  62. mysql_execute "DELETE FROM ezcontentobject_link WHERE from_contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  63. mysql_execute "DELETE FROM ezcontentobject_link WHERE to_contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  64.  
  65. echo "Clean contentobject trash"
  66. mysql_execute "DELETE FROM ezcontentobject_trash WHERE contentobject_id NOT IN (SELECT id FROM ezcontentobject);"
  67.  
  68. TIME_AFTER="$(date +%s)"
  69. ELAPSED="$(expr $TIME_AFTER - $TIME_BEFORE)"
  70. echo ""
  71. echo "Database cleaned in $ELAPSED seconds"
Add Comment
Please, Sign In to add comment