Move handling of mysql-Connection from RedFamParser and RedFamWorker to RedFam-Class and make it protected instead of private

Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=26 FS#26]
This commit is contained in:
2016-03-02 17:00:55 +01:00
parent 58dfd8c86a
commit a97d8c722e

View File

@@ -57,6 +57,9 @@ class RedFam:
@param heading str Original heading of RedFam (Link)
"""
# Database interface
self._mysql = MysqlRedFam( fam_hash )
# Initial attribute values
self._articlesList = articlesList
self._beginning = beginning
@@ -108,6 +111,28 @@ class RedFam:
else:
self._fam_hash = h.hexdigest()
def changed( self ):
"""
Checks wether anything has changed and maybe triggers db update
"""
# On archived red_fams do not delete possibly existing ending
if( not self._ending and self._status > 1
and self._mysql.data[ 'ending' ] ):
self._ending = self._mysql.data[ 'ending' ]
# Since status change means something has changed, update database
if( self._status != self._mysql.data[ 'status' ] or
self._beginning != self._mysql.data[ 'beginning' ] or
self._ending != self._mysql.data[ 'ending' ] or
self._red_page_id != self._mysql.data[ 'red_page_id' ] or
self._heading != self._mysql.data[ 'heading' ]):
self._mysql.update_fam( self._red_page_id, self._heading,
self._beginning, self._ending,
self._status )
@classmethod
def flush_db_cache( cls ):
"""
@@ -194,11 +219,11 @@ class RedFamParser( RedFam ):
"""
# We need a connection to our mysqldb
self.__mysql = MysqlRedFam( )
self.__mysql.get_fam( self._fam_hash )
self._mysql = MysqlRedFam( )
self._mysql.get_fam( self._fam_hash )
if not self.__mysql.data:
self.__mysql.add_fam( self._articlesList, self._heading,
if not self._mysql.data:
self._mysql.add_fam( self._articlesList, self._heading,
self._red_page_id, self._beginning,
self._ending )
@@ -226,6 +251,7 @@ class RedFamParser( RedFam ):
if len( self._articlesList ) > 8:
# For repression in output we need to know the fam hash
self.calc_fam_hash()
jogobot.output(
( "\03{{lightred}}" +
"Maximum number of articles in red_fam exceeded, " +
@@ -289,7 +315,7 @@ class RedFamParser( RedFam ):
"""
# Do not change stati set by worker script etc.
if not self.__mysql.data['status'] > 2:
if not self._mysql.data['status'] > 2:
# No ending, discussion is running:
# Sometimes archived discussions also have no detectable ending
@@ -301,29 +327,8 @@ class RedFamParser( RedFam ):
else:
self._status = 2
else:
self._status = self.__mysql.data[ 'status' ]
def changed( self ):
"""
Checks wether anything has changed and maybe triggers db update
"""
# On archived red_fams do not delete possibly existing ending
if( not self._ending and self._status > 1 and
self.__mysql.data[ 'ending' ] ):
self._ending = self.__mysql.data[ 'ending' ]
# Since status change means something has changed, update database
if( self._status != self.__mysql.data[ 'status' ] or
self._beginning != self.__mysql.data[ 'beginning' ] or
self._ending != self.__mysql.data[ 'ending' ] or
self._red_page_id != self.__mysql.data[ 'red_page_id' ] or
self._heading != self.__mysql.data[ 'heading' ]):
self.__mysql.update_fam( self._red_page_id, self._heading,
self._beginning, self._ending,
self._status )
self._status = self._mysql.data[ 'status' ]
@classmethod
def is_section_redfam_cb( cls, heading ):