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:
@@ -57,6 +57,9 @@ class RedFam:
|
|||||||
@param heading str Original heading of RedFam (Link)
|
@param heading str Original heading of RedFam (Link)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Database interface
|
||||||
|
self._mysql = MysqlRedFam( fam_hash )
|
||||||
|
|
||||||
# Initial attribute values
|
# Initial attribute values
|
||||||
self._articlesList = articlesList
|
self._articlesList = articlesList
|
||||||
self._beginning = beginning
|
self._beginning = beginning
|
||||||
@@ -108,6 +111,28 @@ class RedFam:
|
|||||||
else:
|
else:
|
||||||
self._fam_hash = h.hexdigest()
|
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
|
@classmethod
|
||||||
def flush_db_cache( cls ):
|
def flush_db_cache( cls ):
|
||||||
"""
|
"""
|
||||||
@@ -194,11 +219,11 @@ class RedFamParser( RedFam ):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# We need a connection to our mysqldb
|
# We need a connection to our mysqldb
|
||||||
self.__mysql = MysqlRedFam( )
|
self._mysql = MysqlRedFam( )
|
||||||
self.__mysql.get_fam( self._fam_hash )
|
self._mysql.get_fam( self._fam_hash )
|
||||||
|
|
||||||
if not self.__mysql.data:
|
if not self._mysql.data:
|
||||||
self.__mysql.add_fam( self._articlesList, self._heading,
|
self._mysql.add_fam( self._articlesList, self._heading,
|
||||||
self._red_page_id, self._beginning,
|
self._red_page_id, self._beginning,
|
||||||
self._ending )
|
self._ending )
|
||||||
|
|
||||||
@@ -226,6 +251,7 @@ class RedFamParser( RedFam ):
|
|||||||
if len( self._articlesList ) > 8:
|
if len( self._articlesList ) > 8:
|
||||||
# For repression in output we need to know the fam hash
|
# For repression in output we need to know the fam hash
|
||||||
self.calc_fam_hash()
|
self.calc_fam_hash()
|
||||||
|
|
||||||
jogobot.output(
|
jogobot.output(
|
||||||
( "\03{{lightred}}" +
|
( "\03{{lightred}}" +
|
||||||
"Maximum number of articles in red_fam exceeded, " +
|
"Maximum number of articles in red_fam exceeded, " +
|
||||||
@@ -289,7 +315,7 @@ class RedFamParser( RedFam ):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Do not change stati set by worker script etc.
|
# 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:
|
# No ending, discussion is running:
|
||||||
# Sometimes archived discussions also have no detectable ending
|
# Sometimes archived discussions also have no detectable ending
|
||||||
@@ -301,29 +327,8 @@ class RedFamParser( RedFam ):
|
|||||||
else:
|
else:
|
||||||
self._status = 2
|
self._status = 2
|
||||||
else:
|
else:
|
||||||
self._status = self.__mysql.data[ 'status' ]
|
|
||||||
|
|
||||||
def changed( self ):
|
self._status = self._mysql.data[ 'status' ]
|
||||||
"""
|
|
||||||
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
|
@classmethod
|
||||||
def is_section_redfam_cb( cls, heading ):
|
def is_section_redfam_cb( cls, heading ):
|
||||||
|
|||||||
Reference in New Issue
Block a user